summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2013-05-20 08:36:10 -0700
committerKaz Kylheku <kaz@kylheku.com>2013-05-20 08:36:10 -0700
commitaa5aed38f16aa15dc3c3d2fe4547fb86e26cd6e6 (patch)
tree65cba72084061c9ec1ea861c042fd24426f7fdb8 /lib.c
parent0641abc494c3588d9201d354c92bc6901aa2ef5a (diff)
downloadtxr-aa5aed38f16aa15dc3c3d2fe4547fb86e26cd6e6.tar.gz
txr-aa5aed38f16aa15dc3c3d2fe4547fb86e26cd6e6.tar.bz2
txr-aa5aed38f16aa15dc3c3d2fe4547fb86e26cd6e6.zip
* eval.c (eval_init): Register tok_str as intrinsic.
* lib.c (tok_str): New function. * lib.h (tok_str): Declared. * txr.1: Documented.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index eb34fc62..a1e505c8 100644
--- a/lib.c
+++ b/lib.c
@@ -2060,6 +2060,31 @@ val split_str_set(val str, val set)
return out;
}
+val tok_str(val str, val tok_regex)
+{
+ list_collect_decl (out, iter);
+ val pos = zero;
+
+ for (;;) {
+ cons_bind (new_pos, len, search_regex(str, tok_regex, pos, nil));
+ val end;
+
+ if (!len)
+ break;
+
+ end = plus(new_pos, len);
+
+ list_collect(iter, sub_str(str, new_pos, end));
+
+ pos = end;
+
+ if (len == zero)
+ pos = plus(pos, one);
+ }
+
+ return out;
+}
+
val list_str(val str)
{
const wchar_t *cstr = c_str(str);