@@ -15,12 +15,27 @@ namespace ErrorCodes
1515 extern const int BAD_ARGUMENTS;
1616}
1717
18- static const re2::RE2 range_regex (R"( {([\d]+\.\.[\d]+)})" ); // / regexp for {M..N}, where M and N - non-negative integers
19- static const re2::RE2 enum_regex (R"( {([^{}*,]+[^{}*]*[^{}*,])})" ); // / regexp for {expr1,expr2,expr3}, expr's should be without "{", "}", "*" and ","
18+ namespace
19+ {
20+ struct Regexps
21+ {
22+ static const Regexps & instance ()
23+ {
24+ static Regexps regexps;
25+ return regexps;
26+ }
27+
28+ // / regexp for {M..N}, where M and N - non-negative integers
29+ re2::RE2 range_regex{R"( {([\d]+\.\.[\d]+)})" };
30+
31+ // / regexp for {expr1,expr2,expr3}, expr's should be without "{", "}", "*" and ","
32+ re2::RE2 enum_regex{R"( {([^{}*,]+[^{}*]*[^{}*,])})" };
33+ };
34+ }
2035
2136bool containsRangeGlob (const std::string & input)
2237{
23- return RE2::PartialMatch (input, range_regex);
38+ return RE2::PartialMatch (input, Regexps::instance (). range_regex );
2439}
2540
2641bool containsOnlyEnumGlobs (const std::string & input)
@@ -67,8 +82,8 @@ std::string makeRegexpPatternFromGlobs(const std::string & initial_str_with_glob
6782 std::string_view matched_range;
6883 std::string_view matched_enum;
6984
70- auto did_match_range = RE2::PartialMatch (input, range_regex, &matched_range);
71- auto did_match_enum = RE2::PartialMatch (input, enum_regex, &matched_enum);
85+ auto did_match_range = RE2::PartialMatch (input, Regexps::instance (). range_regex , &matched_range);
86+ auto did_match_enum = RE2::PartialMatch (input, Regexps::instance (). enum_regex , &matched_enum);
7287
7388 // / Enum regex matches ranges, so if they both match and point to the same data,
7489 // / it is a range.
@@ -78,7 +93,7 @@ std::string makeRegexpPatternFromGlobs(const std::string & initial_str_with_glob
7893 // / We matched a range, and range comes earlier than enum
7994 if (did_match_range && (!did_match_enum || matched_range.data () < matched_enum.data ()))
8095 {
81- RE2::FindAndConsume (&input, range_regex, &matched);
96+ RE2::FindAndConsume (&input, Regexps::instance (). range_regex , &matched);
8297 std::string buffer (matched);
8398 oss_for_replacing << escaped_with_globs.substr (current_index, matched_range.data () - escaped_with_globs.data () - current_index - 1 ) << ' (' ;
8499
@@ -122,7 +137,7 @@ std::string makeRegexpPatternFromGlobs(const std::string & initial_str_with_glob
122137 // / We matched enum, and it comes earlier than range.
123138 else if (did_match_enum && (!did_match_range || matched_enum.data () < matched_range.data ()))
124139 {
125- RE2::FindAndConsume (&input, enum_regex, &matched);
140+ RE2::FindAndConsume (&input, Regexps::instance (). enum_regex , &matched);
126141 std::string buffer (matched);
127142
128143 oss_for_replacing << escaped_with_globs.substr (current_index, matched.data () - escaped_with_globs.data () - current_index - 1 ) << ' (' ;
0 commit comments