summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-10-22 13:44:38 -0400
committerKaz Kylheku <kaz@kylheku.com>2011-10-22 13:44:38 -0400
commit70a3b3ae47671a8a73ac517cd7c3f6a4bce782e5 (patch)
treeb0fbceca521bf6ba1fe381999f9239d69a598ee3 /lib.c
parent6729d88a6f8f5fc1ae4ea07b96a979bb6ca71ee8 (diff)
downloadtxr-70a3b3ae47671a8a73ac517cd7c3f6a4bce782e5.tar.gz
txr-70a3b3ae47671a8a73ac517cd7c3f6a4bce782e5.tar.bz2
txr-70a3b3ae47671a8a73ac517cd7c3f6a4bce782e5.zip
Task #11474
* filter.c (filter_equal): New function. (upcase_k, downcase_k): New keyword variables. (filter_init): New keyword variables initialized, and new upcase and downcase filters registered. * filter.h (filter_equal): Declared. * lib.c (tree_find): Takes new argument, the equality test function. (upcase_str, downcase_str): New functions. (do_curry_123_23): New static function. (curry_123_23): New function. * lib.h (tree_find): Declaration updated. (upcase_str, downcase_str, curry_123_23): Declared. * match.c (dest_bind): Updated to take equality function. Uses it and passes it down to tree_find. (v_bind): Filter feature implemented. (h_var, v_try): Add equal_f to dest_bind argument list. * txr.1: Updated to describe new filters and bind arguments.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/lib.c b/lib.c
index c773ca60..98a9a056 100644
--- a/lib.c
+++ b/lib.c
@@ -372,12 +372,13 @@ val memqual(val obj, val list)
return list;
}
-val tree_find(val obj, val tree)
+val tree_find(val obj, val tree, val testfun)
{
- if (equal(obj, tree))
+ if (funcall2(testfun, obj, tree))
return t;
else if (consp(tree))
- return some_satisfy(tree, curry_12_2(func_n2(tree_find), obj), nil);
+ return some_satisfy(tree, curry_123_2(func_n3(tree_find),
+ obj, testfun), nil);
return nil;
}
@@ -843,6 +844,32 @@ val copy_str(val str)
return string(c_str(str));
}
+val upcase_str(val str)
+{
+ val len = length_str(str);
+ wchar_t *dst = (wchar_t *) chk_malloc((c_num(len) + 1) * sizeof *dst);
+ const wchar_t *src = c_str(str);
+ val out = string_own(dst);
+
+ while ((*dst++ = towupper(*src++)))
+ ;
+
+ return out;
+}
+
+val downcase_str(val str)
+{
+ val len = length_str(str);
+ wchar_t *dst = (wchar_t *) chk_malloc((c_num(len) + 1) * sizeof *dst);
+ const wchar_t *src = c_str(str);
+ val out = string_own(dst);
+
+ while ((*dst++ = towlower(*src++)))
+ ;
+
+ return out;
+}
+
val string_extend(val str, val tail)
{
type_check(str, STR);
@@ -1556,6 +1583,16 @@ val curry_123_2(val fun3, val arg1, val arg3)
return func_f1(cons(fun3, cons(arg1, arg3)), do_curry_123_2);
}
+static val do_curry_123_23(val fcons, val arg2, val arg3)
+{
+ return funcall3(car(fcons), cdr(fcons), arg2, arg3);
+}
+
+val curry_123_23(val fun3, val arg1)
+{
+ return func_f2(cons(fun3, arg1), do_curry_123_23);
+}
+
static val do_chain(val fun1_list, val arg)
{
for (; fun1_list; fun1_list = cdr(fun1_list))