Boost logo

Boost Users :

Subject: [Boost-users] Get All Words Offset in String using Boost regex
From: S Nagre (snagre.mumbai_at_[hidden])
Date: 2012-01-05 17:29:07


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::map<int32, int32>OffSetMap;
    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



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net