diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2020-08-11 13:17:48 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2020-08-11 13:17:48 +0200 |
commit | 94c1bdfc898e4cad2577949345adb3e2373c692b (patch) | |
tree | cb146cab8f622c9f37f60433a8d5c0df18203042 /libbuild2/utility.ixx | |
parent | c55c3335c5e86777137c8dcca504af9c1d2cadf1 (diff) |
Review find_option*() iterator version
Diffstat (limited to 'libbuild2/utility.ixx')
-rw-r--r-- | libbuild2/utility.ixx | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/libbuild2/utility.ixx b/libbuild2/utility.ixx index dc8b42a..9a77fae 100644 --- a/libbuild2/utility.ixx +++ b/libbuild2/utility.ixx @@ -139,12 +139,24 @@ namespace build2 return find_option (o, s[var], ic); } + inline bool + compare_option (const char* o, const char* s, bool ic) + { + return s != nullptr && (ic ? icasecmp (s, o) : strcmp (s, o)) == 0; + } + + inline bool + compare_option (const char* o, const string& s, bool ic) + { + return ic ? icasecmp (s, o) == 0 : s == o; + } + template <typename I> - I + inline I find_option (const char* o, I b, I e, bool ic) { for (; b != e; ++b) - if ((ic ? icasecmp (*b, o) : strcmp (*b, o)) == 0) + if (compare_option (o, *b, ic)) return b; return e; @@ -184,17 +196,29 @@ namespace build2 return find_option_prefix (p, s[var], ic); } + inline bool + compare_option_prefix (const char* p, size_t n, const char* s, bool ic) + { + return s != nullptr && (ic ? icasecmp (s, p, n) : strncmp (s, p, n)) == 0; + } + + inline bool + compare_option_prefix (const char* p, size_t n, const string& s, bool ic) + { + return (ic ? icasecmp (s, p, n) : s.compare (0, n, p)) == 0; + } + template <typename I> - I - find_option_prefix (const char* p, I rb, I re, bool ic) + inline I + find_option_prefix (const char* p, I b, I e, bool ic) { size_t n (strlen (p)); - for (; rb != re; ++rb) - if ((ic ? icasecmp (*rb, p, n) : strncmp (*rb, p, n)) == 0) - return rb; + for (; b != e; ++b) + if (compare_option_prefix (p, n, *b, ic)) + return b; - return re; + return e; } template <typename T> |