Ticket #4721: regexbroke.cpp

File regexbroke.cpp, 4.6 KB (added by robin.snyder@…, 12 years ago)

Example of the broken condition and what is expected when working

Line 
1//g++ --static regexbroke.cpp -I /boost_1_44_0/ -L /boost_1_44_0/stage/lib/ -lboost_regex -lpthread
2
3
4
5#include <string>
6#include <iostream>
7#include <boost/regex.hpp>
8using namespace std;
9
10int main(int argc, char* argv[])
11 {
12 bool broke =true;
13 if(argc==2 && argv[1][0]=='1')
14 broke=false;
15
16 //string e="((?<LLPAT01>(?<latd>(([0-8]\\d)|(90)|(\\b\\d)|((?<=[NnSs])\\d?\\d)))((dg)|(deg)|(d))?\\s*(?<latm>(([0-5]\\d)|(\\b\\d)))([':])?\\s*(?<lats>(([0-5]\\d)|(\\b\\d))(\\.\\d+)?)([\":])?\\s*(?<latdir>[NnSs])(([\\s,\"])|by|x|X)*(?<lond>((0\\d\\d)|(1[0-7]\\d)|(180)|(\\b\\d\\d)|(\\b\\d)|((?<=[NnSsEeWw])\\d?\\d)))((dg)|(deg)|(d))?\\s*(?<lonm>(([0-5]\\d)|(\\b\\d)))([':])?\\s*(?<lons>(([0-5]\\d)|(\\b\\d))(\\.\\d+)?)([\":])?\\s*(?<londir>[EeWw])))|((?<LLPAT02>(?<latdir>[NnSs])\\s*(?<latd>(([0-8]\\d)|(90)|(\\b\\d)|((?<=[NnSs])\\d?\\d)))((dg)|(deg)|(d))?\\s*(?<latm>(([0-5]\\d)|(\\b\\d)))([':])?\\s*(?<lats>(([0-5]\\d)|(\\b\\d))(\\.\\d+)?)([\":])?(([\\s,\"])|by|x|X)*(?<londir>[EeWw])\\s*(?<lond>((0\\d\\d)|(1[0-7]\\d)|(180)|(\\b\\d\\d)|(\\b\\d)|((?<=[NnSsEeWw])\\d?\\d)))((dg)|(deg)|(d))?\\s*(?<lonm>(([0-5]\\d)|(\\b\\d)))([':])?\\s*(?<lons>(([0-5]\\d)|(\\b\\d))(\\.\\d+)?)([\":])?))|((?<LLPAT04>(?<latd>(([0-8]\\d)|(90)|(\\b\\d)|((?<=[NnSs])\\d?\\d)))((dg)|(deg)|(d))?\\s*(?<latm>(([0-5]\\d)|(\\b\\d))(\\.\\d+)?)([':])?\\s*(?<latdir>[NnSs])(([\\s,\"])|by|x|X)*(?<lond>((0\\d\\d)|(1[0-7]\\d)|(180)|(\\b\\d\\d)|(\\b\\d)|((?<=[NnSsEeWw])\\d?\\d)))((dg)|(deg)|(d))?\\s*(?<lonm>(([0-5]\\d)|(\\b\\d))(\\.\\d+)?)([':])?\\s*(?<londir>[EeWw])))|((?<LLPAT05>(?<latdir>[NnSs])\\s*(?<latd>(([0-8]\\d)|(90)|(\\b\\d)|((?<=[NnSs])\\d?\\d)))((dg)|(deg)|(d))?\\s*(?<latm>(([0-5]\\d)|(\\b\\d))(\\.\\d+)?)([':])?(([\\s,\"])|by|x|X)*(?<londir>[EeWw])\\s*(?<lond>((0\\d\\d)|(1[0-7]\\d)|(180)|(\\b\\d\\d)|(\\b\\d)|((?<=[NnSsEeWw])\\d?\\d)))((dg)|(deg)|(d))?\\s*(?<lonm>(([0-5]\\d)|(\\b\\d))(\\.\\d+)?)([':])?))|((?<LLPAT07>(?<latd>(([0-8]\\d)|(90)|(\\b\\d)|((?<=[NnSs])\\d?\\d))(\\.\\d+))((dg)|(deg)|(d))?\\s*(?<latdir>[NnSs])(([\\s,\"])|by|x|X)*(?<lond>((0\\d\\d)|(1[0-7]\\d)|(180)|(\\b\\d\\d)|(\\b\\d)|((?<=[NnSsEeWw])\\d?\\d))(\\.\\d+))((dg)|(deg)|(d))?\\s*(?<londir>[EeWw])))|((?<LLPAT08>(?<latdir>[NnSs])\\s*(?<latd>(([0-8]\\d)|(90)|(\\b\\d)|((?<=[NnSs])\\d?\\d))(\\.\\d+))((dg)|(deg)|(d))?(([\\s,\"])|by|x|X)*(?<londir>[EeWw])\\s*(?<lond>((0\\d\\d)|(1[0-7]\\d)|(180)|(\\b\\d\\d)|(\\b\\d)|((?<=[NnSsEeWw])\\d?\\d))(\\.\\d+))((dg)|(deg)|(d))?))";
17 string e1,e2,e3;
18
19 if(broke){
20 e1="\\b(?<DMdS>(?<latd>\\d\\d)(?<latm>\\d\\d)(?<lats>\\d\\d(\\.\\d+)?)\\s+(?<lond>\\d{2,3})(?<lonm>\\d\\d)(?<lons>\\d\\d(\\.\\d+)?))";
21 e2="\\b(?<DdM>(?<latd>\\d\\d)(?<latm>\\d\\d(\\.\\d+)?)\\s+(?<lond>\\d{2,3})(?<lonm>\\d\\d(\\.\\d+)?))";
22 e3="\\b(?<dD>(?<latd>\\d\\d(\\.\\d+)?)\\s+(?<lond>\\d\\d\\d(\\.\\d+)?))";
23 }
24 else{
25 e1="\\b(?<DMdS>(?<DMdS.latd>\\d\\d)(?<DMdS.latm>\\d\\d)(?<DMdS.lats>\\d\\d(\\.\\d+)?)\\s+(?<DMdS.lond>\\d{2,3})(?<DMdS.lonm>\\d\\d)(?<DMdS.lons>\\d\\d(\\.\\d+)?))";
26 e2="\\b(?<DdM>(?<DdM.latd>\\d\\d)(?<DdM.latm>\\d\\d(\\.\\d+)?)\\s+(?<DdM.lond>\\d{2,3})(?<DdM.lonm>\\d\\d(\\.\\d+)?))";
27 e3="\\b(?<dD>(?<dD.latd>\\d\\d(\\.\\d+)?)\\s+(?<dD.lond>\\d\\d\\d(\\.\\d+)?))";
28
29 }
30
31 string reg="("+e1+")|("+e2+")|("+e3+")";
32
33 string::const_iterator start, end;
34 string t = "[23:59] <hoover> location 123456 123456";
35 start = t.begin();
36 end = t.end();
37 boost::regex r(reg, boost::regex::perl | boost::regex::icase);
38 boost::smatch match;
39 boost::match_flag_type flags = boost::match_default;
40 while (boost::regex_search(start, end, match, r, flags)) {
41 cerr << "DMdS:" << match["DMdS"].matched << endl;
42 cerr << "DdM:" << match["DdM"].matched << endl;
43 cerr << "dD:" << match["dD"].matched << endl;
44 string key="";
45 if(broke==false){
46 if( match["DMdS"].matched)
47 key="DMdS.";
48 else if( match["DdM"].matched)
49 key="DdM.";
50 else if( match["dD"].matched)
51 key="dD.";
52 }
53
54 cerr<< match.str()<<endl;
55 cerr << match[1] << endl;
56 cerr << "latd:"<< match[key+"latd"] << endl;
57 cerr << "latm:"<< match[key+"latm"] << endl;
58 cerr << "lats:"<< match[key+"lats"] << endl;
59 cerr << "lond:"<< match[key+"lond"] << endl;
60 cerr << "lonm:"<< match[key+"lonm"] << endl;
61 cerr << "lons:"<< match[key+"lons"] << endl;
62 start = match[0].second;
63 }
64
65 return (0);
66 }