Ticket #10114: regex_iter.cc

File regex_iter.cc, 1.6 KB (added by mkrasowski@…, 8 years ago)

simple program used for testing

Line 
1#include <string>
2#include <iostream>
3#include <cstring>
4
5using namespace std;
6
7#include <boost/regex/icu.hpp>
8using namespace boost;
9
10
11void do_stuff(const string & in, const string & re, bool unicode)
12{
13 if(unicode) {
14 std::cout << "DOING UNICODE:" << std::endl;
15
16 UnicodeString str(in.c_str());
17 u32regex reg = make_u32regex(re);
18
19
20 u32regex_iterator<const UChar*>
21 i(make_u32regex_iterator(str, reg, match_partial | match_perl)),
22 j;
23
24 while(i != j) {
25 std::cout << "got a " << ((*i)[0].matched ? "" : "partial ")
26 << "match legth: " << (*i)[0].length() << " match position: " << i->position()
27 << " matched: " << string( (*i)[0].first, (*i)[0].second ) << std::endl;
28 ++i;
29 }
30 } else {
31 std::cout << "DOING ASCII:" << std::endl;
32
33 string str = in;
34 regex reg(re);
35
36 regex_iterator<string::const_iterator>
37 i(make_regex_iterator(str, reg, match_partial | match_perl)),
38 j;
39
40 while(i != j) {
41 std::cout << "got a " << ((*i)[0].matched ? "" : "partial ")
42 << "match legth: " << (*i)[0].length() << " match position: " << i->position()
43 << " matched: " << string( (*i)[0].first, (*i)[0].second ) << std::endl;
44 ++i;
45 }
46 }
47}
48
49
50int main(int argc, char * argv[]) {
51 do_stuff("in summary in math we are using sum", "summary", true);
52 do_stuff("in summary in math we are using sum", "summary", false);
53
54
55 return 0;
56}