From c3020dee6c91f2694cd098566716f2a4a7794dbe Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 19 Sep 2019 22:37:02 +0300 Subject: Adapt to bracket expressions in wildcard patterns --- mod/build-config-module.cxx | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'mod/build-config-module.cxx') diff --git a/mod/build-config-module.cxx b/mod/build-config-module.cxx index d21849e..1efc514 100644 --- a/mod/build-config-module.cxx +++ b/mod/build-config-module.cxx @@ -362,36 +362,44 @@ namespace brep } path build_config_module:: - dash_components_to_path (const string& s) + dash_components_to_path (const string& pattern) { string r; - for (size_t i (0); i != s.size (); ++i) + size_t nstar (0); + for (const path_pattern_term& pt: path_pattern_iterator (pattern)) { - char c (s[i]); - - switch (c) + switch (pt.type) { - case '-': + case path_pattern_term_type::star: { - r += '/'; + // Replace ** with */**/* and skip all the remaining stars that may + // follow in this sequence. + // + if (nstar == 0) + r += "*"; + else if (nstar == 1) + r += "/**/*"; // The first star is already copied. + break; } - case '*': + case path_pattern_term_type::literal: { - if (s[i + 1] == '*') // Can be '\0'. + // Replace '-' with '/' and fall through otherwise. + // + if (get_literal (pt) == '-') { - r += "*/**/*"; - ++i; + r += '/'; break; } } // Fall through. default: { - r += c; - break; + r.append (pt.begin, pt.end); // Copy the pattern term as is. } } + + nstar = pt.star () ? nstar + 1 : 0; } // Append the trailing slash to match the resulting paths as directories. -- cgit v1.1