aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/functions-builtin.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/functions-builtin.cxx')
-rw-r--r--libbuild2/functions-builtin.cxx25
1 files changed, 25 insertions, 0 deletions
diff --git a/libbuild2/functions-builtin.cxx b/libbuild2/functions-builtin.cxx
index 2acd5b4..6f1b704 100644
--- a/libbuild2/functions-builtin.cxx
+++ b/libbuild2/functions-builtin.cxx
@@ -2,9 +2,13 @@
// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
+#include <sstream>
+
#include <libbuild2/function.hxx>
#include <libbuild2/variable.hxx>
+using namespace std;
+
namespace build2
{
// Return NULL value if an environment variable is not set, untyped value
@@ -41,6 +45,27 @@ namespace build2
f["string"] = [](uint64_t i) {return to_string (i);};
f["string"] = [](name n) {return to_string (n);};
+ // Quote a value returning its string representation. If escape is true,
+ // then also escape (with a backslash) the quote characters being added
+ // (this is useful if the result will be re-parsed, for example as a
+ // Testscript command line).
+ //
+ f["quote"] = [](value* v, optional<value> escape)
+ {
+ if (v->null)
+ return string ();
+
+ untypify (*v); // Reverse to names.
+
+ ostringstream os;
+ to_stream (os,
+ v->as<names> (),
+ true /* quote */,
+ '@' /* pair */,
+ escape && convert<bool> (move (*escape)));
+ return os.str ();
+ };
+
// getenv
//
f["getenv"] = [](string name)