Hello,
I wish to determine the "start" and "length" of all the completed words in
a string using Boost Regex
For example I have a String "*Hello World and Google*"
I would like to create a map like this...
1, 5 //First Character position and Length of Word "Hello"
7, 5 // First Character position and Length of Word World
14, 3 //First Character position and Length of Word "And"
18, 6 // First Character position and Length of Word "Google"
This is the code I have written..
void CreateOffSetMap(std::string completeInStr)
{
std::mapOffSetMap;
std::string escapeChar = "\\" ;
std::string bChar = "b";
std::string dotChar = ".";
std::string findWordInStr = escapeChar + bChar + dotChar + escapeChar +
bChar;
boost::regex regExpression(findWordInStr);
boost::smatch what;
std::string::const_iterator start = completeInStr.begin();
std::string::const_iterator end = completeInStr.end();
while (boost::regex_search(start, end, what, regExpression))
{
int32 foundPos = what.position();
int32 foundLen = what.length();
int32 endOffSet = startOffSet + foundLen;
std::string foundString(start + foundPos, start + foundPos +
foundLen);
OffSetMap[foundPos] = foundLen;
start += foundPos + foundLen;
}
}
But is not working correct as expected, Could Anyone tell me where I am
doing wrong here ?
Thanks in Advance
Subhash