diff options
-rw-r--r-- | build2/utility.cxx | 40 | ||||
-rw-r--r-- | build2/utility.hxx | 25 | ||||
-rw-r--r-- | build2/utility.ixx | 8 |
3 files changed, 38 insertions, 35 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 diff --git a/build2/utility.hxx b/build2/utility.hxx index db6460c..cfdaee0 100644 --- a/build2/utility.hxx +++ b/build2/utility.hxx @@ -511,51 +511,54 @@ namespace build2 bool find_options (initializer_list<const char*>, const cstrings&, bool = false); - // As above but look for an option that has the specified prefix. + // As above but look for an option that has the specified prefix. Return the + // pointer to option or NULL if not found (thus can be used as bool). + // Search backward (which is normall consistent with how options override + // each other). // template <typename T> - bool + const string* find_option_prefix (const char* prefix, T&, const variable&, bool = false); template <typename T> - bool + const string* find_option_prefix (const char* prefix, T&, const char*, bool = false); - bool + const string* find_option_prefix (const char* prefix, const lookup&, bool = false); - bool + const string* find_option_prefix (const char* prefix, const strings&, bool = false); - bool + const char* find_option_prefix (const char* prefix, const cstrings&, bool = false); // As above but look for several option prefixes. // template <typename T> - bool + const string* find_option_prefixes (initializer_list<const char*>, T&, const variable&, bool = false); template <typename T> - bool + const string* find_option_prefixes (initializer_list<const char*>, T&, const char*, bool = false); - bool + const string* find_option_prefixes (initializer_list<const char*>, const lookup&, bool = false); - bool + const string* find_option_prefixes (initializer_list<const char*>, const strings&, bool = false); - bool + const char* find_option_prefixes (initializer_list<const char*>, const cstrings&, bool = false); diff --git a/build2/utility.ixx b/build2/utility.ixx index 0622e99..a726b0c 100644 --- a/build2/utility.ixx +++ b/build2/utility.ixx @@ -131,21 +131,21 @@ namespace build2 } template <typename T> - inline bool + inline const string* find_option_prefix (const char* p, T& s, const variable& var, bool ic) { return find_option_prefix (p, s[var], ic); } template <typename T> - inline bool + inline const string* find_option_prefix (const char* p, T& s, const char* var, bool ic) { return find_option_prefix (p, s[var], ic); } template <typename T> - inline bool + inline const string* find_option_prefixes (initializer_list<const char*> ps, T& s, const variable& var, @@ -155,7 +155,7 @@ namespace build2 } template <typename T> - inline bool + inline const string* find_option_prefixes (initializer_list<const char*> ps, T& s, const char* var, |