summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Krupcale <mkrupcale@matthewkrupcale.com>2020-08-09 09:37:19 -0400
committerMatthew Krupcale <mkrupcale@matthewkrupcale.com>2020-08-09 09:45:37 -0400
commit28537a37ea6b85eeca0a8b3b2532e9aefad1e6ee (patch)
tree6634083d1b9fae5b3d3ff410e0ca2f4e1b16f04f
parent600da2b97e937b9c96791c291cb5e08cd8526bdd (diff)
downloadbuild2-28537a37ea6b85eeca0a8b3b2532e9aefad1e6ee.tar.gz
build2-28537a37ea6b85eeca0a8b3b2532e9aefad1e6ee.tar.xz
build2-28537a37ea6b85eeca0a8b3b2532e9aefad1e6ee.zip
Add iterator-based versions of find_option{,_prefix}
This allows one to use all of the properties of iterators to manipulate the found option.
-rw-r--r--libbuild2/utility.hxx8
-rw-r--r--libbuild2/utility.ixx24
2 files changed, 32 insertions, 0 deletions
diff --git a/libbuild2/utility.hxx b/libbuild2/utility.hxx
index 7a6ada2a..67c46d9b 100644
--- a/libbuild2/utility.hxx
+++ b/libbuild2/utility.hxx
@@ -649,6 +649,10 @@ namespace build2
const char* variable,
bool ignore_case = false);
+ template <typename I>
+ I
+ find_option (const char* option, I begin, I end, bool ignore_case = false);
+
LIBBUILD2_SYMEXPORT bool
find_option (const char* option, const lookup&, bool ignore_case = false);
@@ -702,6 +706,10 @@ namespace build2
const string*
find_option_prefix (const char* prefix, T&, const char*, bool = false);
+ template <typename I>
+ I
+ find_option_prefix (const char* prefix, I rbegin, I rend, bool ignore_case = false);
+
LIBBUILD2_SYMEXPORT const string*
find_option_prefix (const char* prefix, const lookup&, bool = false);
diff --git a/libbuild2/utility.ixx b/libbuild2/utility.ixx
index da9f58b3..dc8b42a2 100644
--- a/libbuild2/utility.ixx
+++ b/libbuild2/utility.ixx
@@ -139,6 +139,17 @@ namespace build2
return find_option (o, s[var], ic);
}
+ template <typename I>
+ 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 <typename T>
inline bool
find_options (const initializer_list<const char*>& os,
@@ -173,6 +184,19 @@ namespace build2
return find_option_prefix (p, s[var], ic);
}
+ template <typename I>
+ 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 <typename T>
inline const string*
find_option_prefixes (const initializer_list<const char*>& ps,