I am writing a web spider and want to use the extended regex library instead of creating complex parsing functions.
I looked at this example:
#include <string>
#include <map>
#include <boost/regex.hpp>
typedef std::map<std::string, int, std::less<std::string> > map_type;
boost::regex expression(
"^(template[[:space:]]*<[^;:{]+>[[:space:]]*)?"
"(class|struct)[[:space:]]*"
"(\\<\\w+\\>([[:blank:]]*\\([^)]*\\))?"
"[[:space:]]*)*(\\<\\w*\\>)[[:space:]]*"
"(<[^;:{]+>[[:space:]]*)?(\\{|:[^;\\{()]*\\{)");
void IndexClasses(map_type& m, const std::string& file)
{
std::string::const_iterator start, end;
start = file.begin();
end = file.end();
boost::match_results<std::string::const_iterator> what;
boost::match_flag_type flags = boost::match_default;
while(regex_search(start, end, what, expression, flags))
{
m[std::string(what[5].first, what[5].second)
+ std::string(what[6].first, what[6].second)]
= what[5].first - file.begin();
start = what[0].second;
flags |= boost::match_prev_avail;
flags |= boost::match_not_bob;
}
}
but, it is somewhat confused (this is my first attempt with boost;)), and I can not find the actual location of the corresponding lines.
So my question is: how do I get the location of all matches?
zajcev
source
share