From d1c55f129cebff527876b5acecef36feb1369f65 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 27 Aug 2018 15:05:09 +0200 Subject: Use butl::path_match() for pattern-specific variable matching --- build2/variable.cxx | 35 ++++++++++------------------------- 1 file 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 // memcmp() +#include // path_match() + #include #include @@ -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? // -- cgit v1.1