aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
authorMatthew Krupcale <mkrupcale@matthewkrupcale.com>2020-08-09 09:37:19 -0400
committerBoris Kolpackov <boris@codesynthesis.com>2020-08-12 13:57:35 +0200
commitca2283bdc00529967f9ccd9bf0097714447af351 (patch)
tree3db34d7239556aa8ba8c708487f325f3edd85073 /libbuild2
parentd72e5f95e70976f9b8bc29a7ace3c354e815ca49 (diff)
Add iterator-based versions of find_option{,_prefix}
This allows one to use all of the properties of iterators to manipulate the found option.
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/utility.hxx16
-rw-r--r--libbuild2/utility.ixx48
2 files changed, 61 insertions, 3 deletions
diff --git a/libbuild2/utility.hxx b/libbuild2/utility.hxx
index 7a6ada2..b747667 100644
--- a/libbuild2/utility.hxx
+++ b/libbuild2/utility.hxx
@@ -633,7 +633,8 @@ namespace build2
F&& get = [] (const string& s) {return s;});
// Check if a specified option is present in the variable or value. T is
- // either target or scope.
+ // either target or scope. For the interator version use rbegin()/rend() to
+ // search backwards.
//
template <typename T>
bool
@@ -649,6 +650,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);
@@ -691,8 +696,9 @@ namespace build2
// 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).
+ // Search backward (which is normally consistent with how options override
+ // each other). For the interator version use rbegin()/rend() to do the
+ // same.
//
template <typename T>
const string*
@@ -702,6 +708,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 begin, I end, bool = 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 da9f58b..9a77fae 100644
--- a/libbuild2/utility.ixx
+++ b/libbuild2/utility.ixx
@@ -139,6 +139,29 @@ 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>
+ inline I
+ find_option (const char* o, I b, I e, bool ic)
+ {
+ for (; b != e; ++b)
+ if (compare_option (o, *b, ic))
+ return b;
+
+ return e;
+ }
+
template <typename T>
inline bool
find_options (const initializer_list<const char*>& os,
@@ -173,6 +196,31 @@ 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>
+ inline I
+ find_option_prefix (const char* p, I b, I e, bool ic)
+ {
+ size_t n (strlen (p));
+
+ for (; b != e; ++b)
+ if (compare_option_prefix (p, n, *b, ic))
+ return b;
+
+ return e;
+ }
+
template <typename T>
inline const string*
find_option_prefixes (const initializer_list<const char*>& ps,