summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-06-10 07:29:56 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-06-10 07:29:56 -0700
commit79f55cbf6c6e7412473e119a02aa637e985721f5 (patch)
tree7f8d7fc468dc5499431e570b3704a22e243999df /lib.c
parent06e308526e9c612eaf6e36c36f2213bb915038e4 (diff)
downloadtxr-79f55cbf6c6e7412473e119a02aa637e985721f5.tar.gz
txr-79f55cbf6c6e7412473e119a02aa637e985721f5.tar.bz2
txr-79f55cbf6c6e7412473e119a02aa637e985721f5.zip
* eval.c (eval_init): Change registration of string_cmp
to cmp_str. Add registrations for str_eq, str_lt, str_gt, str_le, and str_lt. * lib.c (string_cmp): Name changes to cmp_str, and the function fixed so that it actually works. The name change doesn't affect anyone because the function was too broken to use due to the incorrect type dispatch. (string_lt): Name changes to str_lt. (str_eq, str_gt, str_le, str_ge): New functions. * lib.h (string_cmp, string_lt): Declarations renamed. (str_eq, str_gt, str_le, str_ge): New declarations. * txr.1: Document string-cmp to cmp-str rename, that string-lt is deprecated, and the new str<, str>, str>=, str<= and str= functions.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/lib.c b/lib.c
index b0118f45..e8117bf4 100644
--- a/lib.c
+++ b/lib.c
@@ -2499,9 +2499,9 @@ val trim_str(val str)
}
}
-val string_cmp(val astr, val bstr)
+val cmp_str(val astr, val bstr)
{
- switch (TYPE_PAIR(tag(astr), tag(bstr))) {
+ switch (TYPE_PAIR(type(astr), type(bstr))) {
case TYPE_PAIR(LIT, LIT):
case TYPE_PAIR(STR, STR):
case TYPE_PAIR(LIT, STR):
@@ -2522,25 +2522,47 @@ val string_cmp(val astr, val bstr)
val bch = chr_str(bstr, i);
if (ach < bch)
- return num_fast(-1);
+ return one;
else if (ach < bch)
- return num_fast(1);
+ return one;
}
if (length_str_lt(bstr, i))
- return num_fast(-1);
+ return negone;
if (length_str_lt(astr, i))
- return num_fast(1);
+ return negone;
return zero;
}
default:
- uw_throwf(error_s, lit("string-cmp: invalid operands ~s ~s"),
+ uw_throwf(error_s, lit("cmp-str: invalid operands ~s ~s"),
astr, bstr, nao);
}
}
-val string_lt(val astr, val bstr)
+val str_eq(val astr, val bstr)
{
- return wcscmp(c_str(astr), c_str(bstr)) < 0 ? t : nil;
+ return if2(cmp_str(astr, bstr) == zero, t);
+}
+
+val str_lt(val astr, val bstr)
+{
+ return if2(cmp_str(astr, bstr) == negone, t);
+}
+
+val str_gt(val astr, val bstr)
+{
+ return if2(cmp_str(astr, bstr) == one, t);
+}
+
+val str_le(val astr, val bstr)
+{
+ val cmp = cmp_str(astr, bstr);
+ return if2(cmp == zero || cmp == negone, t);
+}
+
+val str_ge(val astr, val bstr)
+{
+ val cmp = cmp_str(astr, bstr);
+ return if2(cmp == zero || cmp == one, t);
}
val int_str(val str, val base)