aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-09-30 19:08:53 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2019-10-01 12:15:10 +0300
commit0e1a28e47753f2b4b4d299fa0b3c3ac80c05dc76 (patch)
tree7e575fd7c0ef1eb6a097b6f84934349ce185b2c2
parentc478a365d8479ca25f6a72d42ecd45dcb9e9569a (diff)
Add support for $string.icasecmp()
-rw-r--r--libbuild2/functions-string.cxx23
-rw-r--r--tests/function/string/buildfile5
-rw-r--r--tests/function/string/testscript27
3 files changed, 55 insertions, 0 deletions
diff --git a/libbuild2/functions-string.cxx b/libbuild2/functions-string.cxx
index 1e93943..55715fe 100644
--- a/libbuild2/functions-string.cxx
+++ b/libbuild2/functions-string.cxx
@@ -21,6 +21,29 @@ namespace build2
//
// f["string"] = [](strings v) {return v;};
+ // Compare ASCII strings ignoring case and returning the boolean value.
+ //
+ f["icasecmp"] = [](string x, string y)
+ {
+ return icasecmp (x, y) == 0;
+ };
+
+ f["icasecmp"] = [](string x, names y)
+ {
+ return icasecmp (x, convert<string> (move (y))) == 0;
+ };
+
+ f["icasecmp"] = [](names x, string y)
+ {
+ return icasecmp (convert<string> (move (x)), y) == 0;
+ };
+
+ f[".icasecmp"] = [](names x, names y)
+ {
+ return icasecmp (convert<string> (move (x)),
+ convert<string> (move (y))) == 0;
+ };
+
// String-specific overloads from builtins.
//
function_family b (m, "builtin");
diff --git a/tests/function/string/buildfile b/tests/function/string/buildfile
new file mode 100644
index 0000000..a5de079
--- /dev/null
+++ b/tests/function/string/buildfile
@@ -0,0 +1,5 @@
+# file : tests/function/string/buildfile
+# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+./: testscript $b
diff --git a/tests/function/string/testscript b/tests/function/string/testscript
new file mode 100644
index 0000000..296e0d1
--- /dev/null
+++ b/tests/function/string/testscript
@@ -0,0 +1,27 @@
+# file : tests/function/string/testscript
+# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+.include ../../common.testscript
+
+: icasecmp
+:
+{
+ : equal
+ :
+ {
+ $* <'print $icasecmp([string] "a", [string] "A")' >'true' : string-string
+ $* <'print $icasecmp([string] "a", "A")' >'true' : string-untyped
+ $* <'print $icasecmp("a", [string] "A")' >'true' : untyped-string
+ $* <'print $string.icasecmp("a", "A")' >'true' : untyped-untyped
+ }
+
+ : different
+ :
+ {
+ $* <'print $icasecmp([string] "a", [string] "b")' >'false' : string-string
+ $* <'print $icasecmp([string] "a", "b")' >'false' : string-untyped
+ $* <'print $icasecmp("a", [string] "b")' >'false' : untyped-string
+ $* <'print $string.icasecmp("a", "b")' >'false' : untyped-untyped
+ }
+}