diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2024-10-28 12:52:11 +0200 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2024-10-28 12:52:11 +0200 |
commit | 0e911d64e71a85d3958689debff0ccbee4c3891a (patch) | |
tree | c6883a7d44b48417956d98924f889a92daf29806 /libbuild2 | |
parent | c10c90efd41294eca8dad0bd3a20abead33032c2 (diff) |
Make .*search() functions not to match empty substrings in non empty strings
Diffstat (limited to 'libbuild2')
-rw-r--r-- | libbuild2/functions-regex.cxx | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/libbuild2/functions-regex.cxx b/libbuild2/functions-regex.cxx index c46f6f5..cac4e54 100644 --- a/libbuild2/functions-regex.cxx +++ b/libbuild2/functions-regex.cxx @@ -138,12 +138,19 @@ namespace build2 // string s (to_string (move (v))); + // Match flags. + // + regex_constants::match_flag_type mf (regex_constants::match_default); + + if (!s.empty ()) + mf |= regex_constants::match_not_null; + if (!match && !subs) - return value (regex_search (s, rge)); // Return boolean value. + return value (regex_search (s, rge, mf)); // Return boolean value. match_results<string::const_iterator> m; - if (regex_search (s, m, rge)) + if (regex_search (s, m, rge, mf)) { assert (!m.empty ()); @@ -483,7 +490,16 @@ namespace build2 for (auto& n: ns) { - if (regex_search (convert<string> (move (n)), rge)) + string s (convert<string> (move (n))); + + // Match flags. + // + regex_constants::match_flag_type mf (regex_constants::match_default); + + if (!s.empty ()) + mf |= regex_constants::match_not_null; + + if (regex_search (s, rge, mf)) return true; } @@ -516,7 +532,14 @@ namespace build2 bool s (n.simple ()); string v (convert<string> (s ? move (n) : name (n))); - if (regex_search (v, rge) == matching) + // Match flags. + // + regex_constants::match_flag_type mf (regex_constants::match_default); + + if (!v.empty ()) + mf |= regex_constants::match_not_null; + + if (regex_search (v, rge, mf) == matching) r.emplace_back (s ? name (move (v)) : move (n)); } |