summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
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;