# # patch "ChangeLog" # from [b0f2be2bbdd4d66c404c825fd335d9c446597cdc] # to [f3568cb45c9228b7d12e25344f07558cfdfa599a] # # patch "globish.cc" # from [42062864963a68b6d468f784dace238974658f3c] # to [c14030e9cdbf777c180f3324d26c18b25d29cf6e] # # patch "globish.hh" # from [c43704114fc9a8866638686f3899749824c49179] # to [bcbaf2efddd720efb786f5f2843890071e42e3d8] # --- ChangeLog +++ ChangeLog @@ -1,5 +1,11 @@ 2005-07-03 Nathaniel Smith + * globish.hh: Document the empty pattern as never matching. + * globish.cc (checked_globish_to_regex): Implement it. + (globish_matcher_test): Check it. + +2005-07-03 Nathaniel Smith + * monotone.texi (Network Service, Hooks): * testsuite.at: * tests/t_netsync_permissions.at: --- globish.cc +++ globish.cc @@ -13,6 +13,9 @@ // // Pattern tranformation: // +// - As a special case, the empty pattern is translated to "$^", which cannot +// match any string. +// // - Any character except those described below are copied as they are. // - The backslash (\) escapes the following character. The escaping // backslash is copied to the regex along with the following character. @@ -45,12 +48,17 @@ L(F("checked_globish_to_regex: input = '%s'\n") % glob); + if (glob == "") + { + regex = "$^"; + // and the below loop will do nothing + } for (std::string::const_iterator i = glob.begin(); i != glob.end(); ++i) { char c = *i; - + N(in_braces < 5, F("braces nested too deep in pattern '%s'") % glob); - + switch(c) { case '*': @@ -84,7 +92,7 @@ break; } } - + N(in_braces == 0, F("run-away brace expression in pattern '%s'") % glob); @@ -196,6 +204,11 @@ BOOST_CHECK(m("bfoobar")); BOOST_CHECK(!m("bfoobarcfoobar")); } + { + globish_matcher m(utf8("*"), utf8("")); + BOOST_CHECK(m("foo")); + BOOST_CHECK(m("")); + } } --- globish.hh +++ globish.hh @@ -20,6 +20,9 @@ // {,,...} - match any of the given items // so like standard globs, except without [] character sets, and with {} // alternation. +// the one strange thing is there is a special-case -- the empty pattern +// matches nothing, not even the empty string. this hardly ever matters, but +// it's nice to have some way to say "don't exclude anything", for instance. #include #include