diff options
Diffstat (limited to 'build2/target.txx')
-rw-r--r-- | build2/target.txx | 51 |
1 files changed, 22 insertions, 29 deletions
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 <const char* ext> bool - target_pattern_fix (const target_type&, const scope&, string& v, bool r) + target_pattern_fix (const target_type&, + const scope&, + string&, + optional<string>& 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 <const char* var, const char* def> 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<string>& 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; |