|
Boost Users : |
From: Lynn Allan (l_d_allan_at_[hidden])
Date: 2006-04-12 18:26:25
> A better approach would be to use iterators.
>
> // Begin searching 32 characters into altDow
> regex_search( altDow.begin() + 32, altDow.end(), what, rex )
>
> Note #1: the match results will now contain iterators into altDow,
> but
> position offsets will be relative to the start of the search, not
> the
> start of altDow.
Is the following getting closer to "best practice" to use
xpressive-static for the kinds of specialized searches I'm attempting.
When I'm further along on the learning curve, I'll try to prepare some
"apples and apples" timing comparisons between boost::regex,
xpressive, spirit, a hand-tuned state-machine searcher, and an
automatic FSM generator utility.
I think I'm conforming to the guidelines on this page:
X:\DevTools\Boost\libs\xpressive\doc\html\boost_xpressive\user_s_guide\tips_n_tricks.html
except I don't understand how to specify
syntax_option_type::optimize
(does it apply to xpressive-static, or only xpressive-dynamic)?
boost::xpressive::regex_constants::syntax_option_type flags =
boost::xpressive::regex_constants::optimize;
sregex rexStatic =
(s1 = (as_xpr("Sunday") | "Sun")) |
(s2 = (as_xpr("Monday") | "Mon")) |
(s3 = (as_xpr("Tuesday") | "Tue")) |
(s4 = (as_xpr("Wednesday") | "Wed")) |
(s5 = (as_xpr("Thursday") | "Thu")) |
(s6 = (as_xpr("Friday") | "Fri")) |
(s7 = (as_xpr("Saturday") | "Sat")) ;
//??? rexStatic.compile(rexStatic, flags);
smatch what;
std::string testStr =
"Alternate days of the week are Tue and Thursday and Sat and
Monday. "
"And then Monday and Wed and Friday and Sun. ";
std::string::const_iterator start = testStr.begin();
std::string::const_iterator finish = testStr.end();
int foundCount = 0;
while (regex_search(start, finish, what, rexStatic)) {
foundCount++;
size_t limit = what.size();
size_t matchIndex = 1;
while (matchIndex <= limit) {
if (what[matchIndex].matched == true) {
break;
}
++matchIndex;
}
#ifdef _DEBUG
cout << "FoundCount: " << foundCount
<< " Index: " << static_cast<int>(matchIndex)
<< " what[0]: " << what[0] << endl;
#endif
start = what[0].second;
}
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