From e4f41c7319261b9585bd501256664679457e1d9d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 7 Aug 2018 14:59:07 +0200 Subject: Add support for default extension specification, trailing dot escaping For example: cxx{*}: extension = cxx cxx{foo} # foo.cxx cxx{foo.test} # foo.test (probably what we want...) cxx{foo.test...} # foo.test.cxx (... is this) cxx{foo..} # foo. cxx{foo....} # foo.. cxx{foo.....} # error (must come in escape pair) --- build2/target.txx | 51 ++++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) (limited to 'build2/target.txx') diff --git a/build2/target.txx b/build2/target.txx index d832d6b..8030c1a 100644 --- a/build2/target.txx +++ b/build2/target.txx @@ -55,29 +55,27 @@ namespace build2 template bool - target_pattern_fix (const target_type&, const scope&, string& v, bool r) + target_pattern_fix (const target_type&, + const scope&, + string&, + optional& e, + bool r) { - size_t p (path::traits::find_extension (v)); - if (r) { // If we get called to reverse then it means we've added the extension - // in the first place. So simply strip it. + // in the first place. // - assert (p != string::npos); - v.resize (p); + assert (e); + e = nullopt; } // // We only add our extension if there isn't one already. // - else if (p == string::npos) + else if (!e) { - if (*ext != '\0') // Don't add empty extension (means no extension). - { - v += '.'; - v += ext; - return true; - } + e = ext; + return true; } return false; @@ -115,35 +113,30 @@ namespace build2 template bool - target_pattern_var (const target_type& tt, const scope& s, string& v, bool r) + target_pattern_var (const target_type& tt, + const scope& s, + string&, + optional& e, + bool r) { - size_t p (path::traits::find_extension (v)); - if (r) { // If we get called to reverse then it means we've added the extension - // in the first place. So simply strip it. + // in the first place. // - assert (p != string::npos); - v.resize (p); + assert (e); + e = nullopt; } // // We only add our extension if there isn't one already. // - else if (p == string::npos) + else if (!e) { // Use empty name as a target since we only want target type/pattern- // specific variables that match any target (e.g., '*' but not '*.txt'). // - if (auto e = target_extension_var_impl (tt, string (), s, var, def)) - { - if (!e->empty ()) // Don't add empty extension (means no extension). - { - v += '.'; - v += *e; - return true; - } - } + if ((e = target_extension_var_impl (tt, string (), s, var, def))) + return true; } return false; -- cgit v1.1