Debian Codegraph @

yo/stl/examples/regexplain.cc

raw
1 #include <string>
2 #include <iostream>
3 #include <regex>
4 #include <iterator>
5
6 using namespace std;
7
8 //code
9 bool modify(string const &match);
10 size_t replace(string &target, string::iterator begin, string match);
11
12 int main()
13 {
14 string target("... oh, when the Saints, ...");
15
16 regex re("\\w+");
17 smatch match;
18 size_t offset = 0;
19 while (true)
20 {
21 auto begin = target.begin() + offset;
22 if (not regex_search(string::const_iterator(begin),
23 target.cend(), match, re))
24 break;
25
26 size_t pos = match.position(0);
27
28 offset += pos +
29 modify(match[0]) ?
30 replace(target, begin + pos, match[0])
31 :
32 match.length(0);
33 }
34 cout << "new text: " << target << '\n';
35 }
36 //=