From 5f27918e56f7cb89226556836e35a1a64ba5cd99 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 19 Oct 2019 17:11:24 +0200 Subject: Add find_stem() utility function --- libbuild2/utility.hxx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'libbuild2/utility.hxx') 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. -- cgit v1.1