Changeset 19183 for trunk/FACT++
- Timestamp:
- 08/19/18 17:44:49 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/rootifysql.cc
r19180 r19183 1 1 #include "Database.h" 2 2 3 #include <regex>4 5 3 #include <boost/algorithm/string/join.hpp> 4 #include <boost/regex.hpp> 6 5 #include <boost/tokenizer.hpp> 7 6 #include <boost/algorithm/string.hpp> … … 120 119 vector<string> vec; 121 120 122 string substitute(string _str, const regex &expr)123 { 124 smatch match;125 while ( regex_search(_str, match, expr,regex_constants::format_first_only))126 { 127 const auto &len = match.length( 0);128 const auto &pos = match.position( 0);129 const auto &str = match.str( 0);121 string substitute(string _str, const boost::regex &expr) 122 { 123 boost::smatch match; 124 while (boost::regex_search(_str, match, expr, boost::regex_constants::format_first_only)) 125 { 126 const auto &len = match.length(); 127 const auto &pos = match.position(); 128 const auto &str = match.str(); 130 129 131 130 const auto it = find(vec.cbegin(), vec.cend(), str); … … 143 142 string substitute(const string &str, const string &expr) 144 143 { 145 return substitute(str, regex(expr));144 return substitute(str, boost::regex(expr)); 146 145 } 147 146 … … 151 150 { 152 151 // search for "KEYWORD expression" 153 regex reg("\\{[0-9]+\\}"); 154 155 //smatch match; 156 smatch match; 157 while (regex_search(str, match, reg, regex_constants::format_first_only)) 158 { 159 const auto &len = match.length(0); 160 const auto &pos = match.position(0); 161 const auto &arg = match.str(0); // Argument 152 boost::regex reg("\\{[0-9]+\\}"); 153 154 boost::smatch match; 155 while (boost::regex_search(str, match, reg, boost::regex_constants::format_first_only)) 156 { 157 const auto &len = match.length(); 158 const auto &pos = match.position(); 159 const auto &arg = match.str(); // Argument 162 160 163 161 const auto idx = atoi(arg.c_str()+1); … … 220 218 221 219 // Matche: ( _com )? ( ( _tok )? ( _exp ) | ( _tok ) ) 222 regex reg("("+_com+")?" + "(" + "("+_tok+")?"+"("+_exp+")" + "|" + "("+_tok+")" + ")");223 224 smatch match;225 while ( regex_search(str, match, reg,regex_constants::format_first_only))220 boost::regex reg("("+_com+")?" + "(" + "("+_tok+")?"+"("+_exp+")" + "|" + "("+_tok+")" + ")"); 221 222 boost::smatch match; 223 while (boost::regex_search(str, match, reg, boost::regex_constants::format_first_only)) 226 224 { 227 225 … … 258 256 } 259 257 260 str = str.substr(match.position( 0)+match.length(0));258 str = str.substr(match.position()+match.length()); 261 259 } 262 260 } … … 490 488 491 489 vector<string> variables; 492 for ( const auto &var : vars)493 variables.emplace_back('@'+var .substr(4)+":="+Tools::Trim(conf.Get<string>(var)));490 for (auto var=vars.cbegin(); var!=vars.cend(); var++) 491 variables.emplace_back('@'+var->substr(4)+":="+Tools::Trim(conf.Get<string>(*var))); 494 492 495 493 // ------------------------------------------------------------------------- … … 526 524 map<string, vector<string>> envs; 527 525 528 for (const auto &env : conf.GetWildcardOptions("env.*")) 529 envs[env.substr(4)] = conf.Vec<string>(env); 530 531 for (const auto &env : conf.GetWildcardOptions("list.*")) 532 { 533 const string fname = conf.Get<string>(env); 534 const string &ident = env.substr(5); 526 const auto &envs1 = conf.GetWildcardOptions("env.*"); 527 for (auto env=envs1.cbegin(); env!=envs1.cend(); env++) 528 envs[env->substr(4)] = conf.Vec<string>(*env); 529 530 const auto &envs2 = conf.GetWildcardOptions("list.*"); 531 for (auto env=envs2.cbegin(); env!=envs2.cend(); env++) 532 { 533 const string fname = conf.Get<string>(*env); 534 const string &ident = env->substr(5); 535 535 536 536 ifstream fin(fname); … … 540 540 return 6; 541 541 } 542 543 542 for (string line; getline(fin, line); ) 544 543 { … … 552 551 } 553 552 554 for ( const auto &env : envs)555 { 556 regex rexpr("\\$(\\{"+env.first+"\\}|"+env.first+"\\b)");557 query = regex_replace(query, rexpr, boost::join(env.second, ", "));553 for (auto env=envs.cbegin(); env!=envs.cend(); env++) 554 { 555 boost::regex rexpr("\\$(\\{"+env->first+"\\}|"+env->first+"\\b)"); 556 query = boost::regex_replace(query, rexpr, boost::join(env->second, ", ")); 558 557 } 559 558 … … 591 590 // --------------------------- Connect to database ------------------------------------------------- 592 591 593 if ( query.back()!='\n')592 if (*query.rbegin()!='\n') 594 593 query += '\n'; 595 594 … … 815 814 816 815 bool found = false; 817 for ( const auto &pattern: _ignore)818 { 819 if ( regex_match(l[i], regex(pattern)))816 for (auto pattern=_ignore.cbegin(); pattern!=_ignore.cend(); pattern++) 817 { 818 if (boost::regex_match(l[i], boost::regex(*pattern))) 820 819 { 821 820 found = true;
Note:
See TracChangeset
for help on using the changeset viewer.