From 1276a28b88295caf27c5df97d2e61b28feed3999 Mon Sep 17 00:00:00 2001 From: Matthew Krupcale Date: Sun, 9 Aug 2020 09:37:19 -0400 Subject: Add iterator-based versions of find_option{,_prefix} This allows one to use all of the properties of iterators to manipulate the found option. --- libbuild2/utility.ixx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'libbuild2/utility.ixx') diff --git a/libbuild2/utility.ixx b/libbuild2/utility.ixx index da9f58b..dc8b42a 100644 --- a/libbuild2/utility.ixx +++ b/libbuild2/utility.ixx @@ -139,6 +139,17 @@ namespace build2 return find_option (o, s[var], ic); } + template + 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) + return b; + + return e; + } + template inline bool find_options (const initializer_list& os, @@ -173,6 +184,19 @@ namespace build2 return find_option_prefix (p, s[var], ic); } + template + I + find_option_prefix (const char* p, I rb, I re, bool ic) + { + size_t n (strlen (p)); + + for (; rb != re; ++rb) + if ((ic ? icasecmp (*rb, p, n) : strncmp (*rb, p, n)) == 0) + return rb; + + return re; + } + template inline const string* find_option_prefixes (const initializer_list& ps, -- cgit v1.1