From 399b4b6a5082aa6f14a98bc50b29baeca686aa39 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 11 Jun 2013 16:15:34 -0700 Subject: * 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. --- lib.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib.c') 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; -- cgit v1.2.3