diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2018-08-27 15:05:09 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2018-08-27 15:05:09 +0200 |
commit | d1c55f129cebff527876b5acecef36feb1369f65 (patch) | |
tree | c0aa38bfe330474b2414168f74d9d5440155062a | |
parent | 32e04ad4b4a8dec07836b7c9fcf90fe72a006990 (diff) |
Use butl::path_match() for pattern-specific variable matching
-rw-r--r-- | build2/variable.cxx | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/build2/variable.cxx b/build2/variable.cxx index c304d0c..3fb2fc0 100644 --- a/build2/variable.cxx +++ b/build2/variable.cxx @@ -6,6 +6,8 @@ #include <cstring> // memcmp() +#include <libbutl/filesystem.mxx> // path_match() + #include <build2/context.hxx> #include <build2/diagnostics.hxx> @@ -1478,34 +1480,17 @@ namespace build2 for (auto j (m.rbegin ()); j != m.rend (); ++j) { - const string& p (j->first); - - size_t nn (name.size ()); - size_t pn (p.size ()); - - if (nn < pn - 1) // One for '*'. - continue; - - size_t w (p.find ('*')); - assert (w != string::npos); - - // Compare prefix. - // - if (w != 0 && - name.compare (0, w, p, 0, w) != 0) - continue; - - ++w; // First suffix character. - pn -= w; // Suffix length. - - // Compare suffix. - // - if (pn != 0 && - name.compare (nn - pn, pn, p, w, pn) != 0) - continue; + const string& pat (j->first); //@@ TODO: should we detect ambiguity? 'foo-*' '*-foo' and 'foo-foo'? // Right now the last defined will be used. + // + if (pat != "*") + { + if (name.size () < pat.size () - 1 || // One for '*' or '?'. + !butl::path_match (pat, name)) + continue; + } // Ok, this pattern matches. But is there a variable? // |