summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2013-06-11 16:15:34 -0700
committerKaz Kylheku <kaz@kylheku.com>2013-06-11 16:15:34 -0700
commit399b4b6a5082aa6f14a98bc50b29baeca686aa39 (patch)
treefcf71aad074e38aecc2a13a192756791a1e02783 /lib.c
parenta6b0130ceaeadce6845d698fb68712dc2786e918 (diff)
downloadtxr-399b4b6a5082aa6f14a98bc50b29baeca686aa39.tar.gz
txr-399b4b6a5082aa6f14a98bc50b29baeca686aa39.tar.bz2
txr-399b4b6a5082aa6f14a98bc50b29baeca686aa39.zip
* eval.c (eval_init): tok-str acquires new parameter
* lib.c (tok_str): New parameter, keep_sep. * lib.h (tok_str): Declaration updated. * txr.1: Documentation for tok-str updated.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib.c b/lib.c
index 97844d32..25ecb91d 100644
--- a/lib.c
+++ b/lib.c
@@ -2060,7 +2060,7 @@ val split_str_set(val str, val set)
return out;
}
-val tok_str(val str, val tok_regex)
+val tok_str(val str, val tok_regex, val keep_sep)
{
list_collect_decl (out, iter);
val pos = zero;
@@ -2069,11 +2069,17 @@ val tok_str(val str, val tok_regex)
cons_bind (new_pos, len, search_regex(str, tok_regex, pos, nil));
val end;
- if (!len)
+ if (!len) {
+ if (keep_sep)
+ list_collect(iter, sub_str(str, pos, t));
break;
+ }
end = plus(new_pos, len);
+ if (keep_sep)
+ list_collect(iter, sub_str(str, pos, new_pos));
+
list_collect(iter, sub_str(str, new_pos, end));
pos = end;