aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/functions-json.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/functions-json.cxx')
-rw-r--r--libbuild2/functions-json.cxx23
1 files changed, 23 insertions, 0 deletions
diff --git a/libbuild2/functions-json.cxx b/libbuild2/functions-json.cxx
index 5715e13..e06d9a5 100644
--- a/libbuild2/functions-json.cxx
+++ b/libbuild2/functions-json.cxx
@@ -308,5 +308,28 @@ namespace build2
}
};
#endif
+
+ // $size(<json-set>)
+ // $size(<json-map>)
+ //
+ // Return the number of elements in the sequence.
+ //
+ f["size"] += [] (set<json_value> v) {return v.size ();};
+ f["size"] += [] (map<json_value, json_value> v) {return v.size ();};
+
+ // $keys(<json-map>)
+ //
+ // Return the list of keys in a json map as a json array.
+ //
+ // Note that the result is sorted in ascending order.
+ //
+ f["keys"] += [](map<json_value, json_value> v)
+ {
+ json_value r (json_type::array);
+ r.array.reserve (v.size ());
+ for (pair<const json_value, json_value>& p: v)
+ r.array.push_back (p.first); // @@ PERF: use C++17 map::extract() to steal.
+ return r;
+ };
}
}