aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbuild2/functions-string.cxx12
-rw-r--r--tests/function/string/testscript7
2 files changed, 19 insertions, 0 deletions
diff --git a/libbuild2/functions-string.cxx b/libbuild2/functions-string.cxx
index da4fe02..f458a59 100644
--- a/libbuild2/functions-string.cxx
+++ b/libbuild2/functions-string.cxx
@@ -43,6 +43,18 @@ namespace build2
convert<string> (move (y))) == 0;
};
+ // Trim.
+ //
+ f["trim"] = [](string s)
+ {
+ return trim (move (s));
+ };
+
+ f[".trim"] = [](names s)
+ {
+ return names {name (trim (convert<string> (move (s))))};
+ };
+
// String-specific overloads from builtins.
//
function_family b (m, "builtin");
diff --git a/tests/function/string/testscript b/tests/function/string/testscript
index d42add7..9275fe5 100644
--- a/tests/function/string/testscript
+++ b/tests/function/string/testscript
@@ -24,3 +24,10 @@
$* <'print $string.icasecmp("a", "b")' >'false' : untyped-untyped
}
}
+
+: trim
+:
+{
+ $* <'print $trim([string] " a ")' >'a' : string
+ $* <'print $string.trim( " a ")' >'a' : untyped
+}