diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2018-01-05 15:06:24 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2018-01-05 15:10:01 +0200 |
commit | d6427addaf7de41d401dd2a871b4789022e5f7cf (patch) | |
tree | 49d98807682116c04fc11842f2fb53745434820a /build2/utility.cxx | |
parent | 1eff61b00307b9f0081dbf062f6f55e5d4771e52 (diff) |
Extend find_option_prefix() to return option
Diffstat (limited to 'build2/utility.cxx')
-rw-r--r-- | build2/utility.cxx | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/build2/utility.cxx b/build2/utility.cxx index 8d63059..280edd3 100644 --- a/build2/utility.cxx +++ b/build2/utility.cxx @@ -397,73 +397,73 @@ namespace build2 return false; } - bool + const string* find_option_prefix (const char* p, const lookup& l, bool ic) { - return l && find_option_prefix (p, cast<strings> (l), ic); + return l ? find_option_prefix (p, cast<strings> (l), ic) : nullptr; } - bool + const string* find_option_prefix (const char* p, const strings& strs, bool ic) { size_t n (strlen (p)); - for (const string& s: strs) + for (const string& s: reverse_iterate (strs)) if ((ic ? casecmp (s, p, n) : s.compare (0, n, p)) == 0) - return true; + return &s; - return false; + return nullptr; } - bool + const char* find_option_prefix (const char* p, const cstrings& cstrs, bool ic) { size_t n (strlen (p)); - for (const char* s: cstrs) + for (const char* s: reverse_iterate (cstrs)) if (s != nullptr && (ic ? casecmp (s, p, n) : strncmp (s, p, n)) == 0) - return true; + return s; - return false; + return nullptr; } - bool + const string* find_option_prefixes (initializer_list<const char*> ps, const lookup& l, bool ic) { - return l && find_option_prefixes (ps, cast<strings> (l), ic); + return l ? find_option_prefixes (ps, cast<strings> (l), ic) : nullptr; } - bool + const string* find_option_prefixes (initializer_list<const char*> ps, const strings& strs, bool ic) { - for (const string& s: strs) + for (const string& s: reverse_iterate (strs)) for (const char* p: ps) if ((ic ? casecmp (s, p, strlen (p)) : s.compare (0, strlen (p), p)) == 0) - return true; + return &s; - return false; + return nullptr; } - bool + const char* find_option_prefixes (initializer_list<const char*> ps, const cstrings& cstrs, bool ic) { - for (const char* s: cstrs) + for (const char* s: reverse_iterate (cstrs)) if (s != nullptr) for (const char* p: ps) if ((ic ? casecmp (s, p, strlen (p)) : strncmp (s, p, strlen (p))) == 0) - return true; + return s; - return false; + return nullptr; } string |