Ignore:
Timestamp:
08/14/18 22:25:32 (6 years ago)
Author:
tbretz
Message:
Better handling of the replacement for the filename.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/root2sql.cc

    r19164 r19166  
    191191        "For example --const.mycolumn=42 would insert 42 into a column called mycolumn. "
    192192        "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"
    196197        "\n"
    197198        "Usually the previously defined constant values are helpful to create an index "
     
    332333int main(int argc, const char* argv[])
    333334{
     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
    334343    Time start;
    335344
     
    450459
    451460        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)
    458470            {
    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;
    464475            }
    465476        }
Note: See TracChangeset for help on using the changeset viewer.