aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/utility.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-10-19 17:11:24 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-10-19 17:11:24 +0200
commit5f27918e56f7cb89226556836e35a1a64ba5cd99 (patch)
tree5a6fd47065c1bf9c418fc7cea72da67a565e50f7 /libbuild2/utility.hxx
parent9d90382e1282045638ede144b89c7e94f4739466 (diff)
Add find_stem() utility function
Diffstat (limited to 'libbuild2/utility.hxx')
-rw-r--r--libbuild2/utility.hxx14
1 files changed, 14 insertions, 0 deletions
diff --git a/libbuild2/utility.hxx b/libbuild2/utility.hxx
index 0422786..536898e 100644
--- a/libbuild2/utility.hxx
+++ b/libbuild2/utility.hxx
@@ -686,6 +686,20 @@ namespace build2
const cstrings&,
bool = false);
+ // Find in the string the stem separated from other characters with the
+ // specified separators or begin/end of the string. Return the stem's
+ // position or npos if not found.
+ //
+ size_t
+ find_stem (const string&, size_t pos, size_t n,
+ const char* stem, const char* seps = "-_.");
+
+ inline size_t
+ find_stem (const string& s, const char* stem, const char* seps = "-_.")
+ {
+ return find_stem (s, 0, s.size (), stem, seps);
+ }
+
// Apply the specified substitution (stem) to a '*'-pattern. If pattern is
// NULL or empty, then return the stem itself. Assume the pattern is valid,
// i.e., contains a single '*' character.