diff options
Diffstat (limited to 'libbuild2/functions-string.cxx')
-rw-r--r-- | libbuild2/functions-string.cxx | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/libbuild2/functions-string.cxx b/libbuild2/functions-string.cxx index 8e5a315..b332efa 100644 --- a/libbuild2/functions-string.cxx +++ b/libbuild2/functions-string.cxx @@ -119,14 +119,16 @@ namespace build2 }; // $size(<strings>) + // $size(<string-map>) // $size(<string>) // - // First form: return the number of elements in the sequence. + // First two forms: return the number of elements in the sequence. // - // Second form: return the number of characters (bytes) in the string. + // Third form: return the number of characters (bytes) in the string. // - f["size"] += [] (strings v) {return v.size ();}; - f["size"] += [] (string v) {return v.size ();}; + f["size"] += [] (strings v) {return v.size ();}; + f["size"] += [] (map<string, string> v) {return v.size ();}; + f["size"] += [] (string v) {return v.size ();}; // $sort(<strings> [, <flags>]) // @@ -204,6 +206,21 @@ namespace build2 return find_index (vs, move (v), move (fs)); }; + // $keys(<string-map>) + // + // Return the list of keys in a string map. + // + // Note that the result is sorted in ascending order. + // + f["keys"] += [](map<string, string> v) + { + strings r; + r.reserve (v.size ()); + for (pair<const string, string>& p: v) + r.push_back (p.first); // @@ PERF: use C++17 map::extract() to steal. + return r; + }; + // String-specific overloads from builtins. // function_family b (m, "builtin"); |