Changeset 19166
- Timestamp:
- 08/14/18 22:25:32 (6 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/fits2sql.cc
r19165 r19166 184 184 "For example --const.mycolumn=42 would insert 42 into a column called mycolumn. " 185 185 "The column is created as INT UNSIGNED as default which can be altered by " 186 "--sql-type. A special case is a value of the form `/regex/N/`. Here, the given " 187 "regular expression is applied to the filename and N specifies the N-th " 188 "sub-sequence which matches. To debug what matches, verbosity can be set to 3.\n" 186 "--sql-type. A special case is a value of the form `/regex/format/`. Here, the given " 187 "regular expression is applied to the filename and it is newly formated with " 188 "the new format string. For details on how backreferences work, see for example " 189 "the man-page of the sed utility.\n" 189 190 "\n" 190 191 "Usually the previously defined constant values are helpful to create an index " … … 425 426 426 427 boost::smatch match; 427 if (boost::regex_match(val, match, boost::regex("\\/(.+)\\/([0-9]*)\\/"))) 428 { 429 string s = match[1]; 430 size_t r = atoi(match[2].str().c_str()); 431 432 if (boost::regex_search(file, match, boost::regex(s))) 428 if (boost::regex_match(val, match, boost::regex("\\/(.+)(?<!\\\\)\\/(.*)(?<!\\\\)\\/"))) 429 { 430 const string reg = match[1]; 431 const string fmt = match[2]; 432 433 val = boost::regex_replace(file, boost::regex(reg), fmt.empty()?"$0":fmt, 434 boost::regex_constants::format_default|boost::regex_constants::format_no_copy); 435 436 if (verbose>0) 433 437 { 434 if (verbose>2) 435 for (size_t i=0; i<match.size(); i++) 436 cout << "Regex match " << setw(2) << i << ": `" << match[i] << "`" << endl; 437 438 val = match[r]; 438 cout << "Regular expression detected for constant column `" << *it << "`\n"; 439 cout << "Filename converted with /" << reg << "/ to /" << fmt << "/\n"; 440 cout << "Filename: " << file << '\n'; 441 cout << "Result: " << file << endl; 439 442 } 440 443 } -
trunk/FACT++/src/root2sql.cc
r19164 r19166 191 191 "For example --const.mycolumn=42 would insert 42 into a column called mycolumn. " 192 192 "The column is created as INT UNSIGNED as default which can be altered by " 193 "--sql-type. A special case is a value of the form `/regex/N/`. Here, the given " 194 "regular expression is applied to the filename and N specifies the N-th " 195 "sub-sequence which matches. To debug what matches, verbosity can be set to 3.\n" 193 "--sql-type. A special case is a value of the form `/regex/format/`. Here, the given " 194 "regular expression is applied to the filename and it is newly formated with " 195 "the new format string. Uses the standard formatting rules to replace matches " 196 "(those used by ECMAScript's replace method).\n" 196 197 "\n" 197 198 "Usually the previously defined constant values are helpful to create an index " … … 332 333 int main(int argc, const char* argv[]) 333 334 { 335 string input = "/this/is/my/dir/2018/12/13/12345_789_I.root"; 336 boost::regex rgx("([0-9]+)_([0-9]+)"); 337 338 boost::smatch ma; 339 cout << boost::regex_replace(input, rgx, "$1$2", boost::regex_constants::format_default|boost::regex_constants::format_no_copy) << endl; 340 341 return 1; 342 334 343 Time start; 335 344 … … 450 459 451 460 boost::smatch match; 452 if (boost::regex_match(val, match, boost::regex("\\/(.+)\\/([0-9]*)\\/"))) 453 { 454 string s = match[1]; 455 size_t r = atoi(match[2].str().c_str()); 456 457 if (boost::regex_search(file, match, boost::regex(s))) 461 if (boost::regex_match(val, match, boost::regex("\\/(.+)(?<!\\\\)\\/(.*)(?<!\\\\)\\/"))) 462 { 463 const string reg = match[1]; 464 const string fmt = match[2]; 465 466 val = boost::regex_replace(file, boost::regex(reg), fmt.empty()?"$0":fmt, 467 boost::regex_constants::format_default|boost::regex_constants::format_no_copy); 468 469 if (verbose>0) 458 470 { 459 if (verbose>2) 460 for (size_t i=0; i<match.size(); i++) 461 cout << "Regex match " << setw(2) << i << ": `" << match[i] << "`" << endl; 462 463 val = match[r]; 471 cout << "Regular expression detected for constant column `" << *it << "`\n"; 472 cout << "Filename converted with /" << reg << "/ to /" << fmt << "/\n"; 473 cout << "Filename: " << file << '\n'; 474 cout << "Result: " << file << endl; 464 475 } 465 476 }
Note:
See TracChangeset
for help on using the changeset viewer.