diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-09-16 06:55:59 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-09-16 06:55:59 -0700 |
commit | 6b40915a50db3159394221a7b6b46cbb74dae606 (patch) | |
tree | f3e84df93663617030daedd662ca7c7bc1546acb /lib.c | |
parent | 73f7e2e1c2352cc1da6784190468c24c6e003655 (diff) | |
download | txr-6b40915a50db3159394221a7b6b46cbb74dae606.tar.gz txr-6b40915a50db3159394221a7b6b46cbb74dae606.tar.bz2 txr-6b40915a50db3159394221a7b6b46cbb74dae606.zip |
split-str gains ability to keep separating pieces.
* eval.c (eval_init): Register split-str to split_str_keep,
with optional argument.
* lib.c (split_str_keep): New function, formed from
split_str, with third argument.
(split_str): Reduced to wrapper around split_str_keep.
Thus we don't have to update umpteen existing calls
with an extra nil parameter.
* lib.h (split_str_keep): Declared.
* txr.1: Documented new optional argument of split-str.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -3807,8 +3807,10 @@ val scat(val sep, ...) return ret; } -val split_str(val str, val sep) +val split_str_keep(val str, val sep, val keep_sep) { + keep_sep = default_bool_arg(keep_sep); + if (regexp(sep)) { list_collect_decl (out, iter); val pos = zero; @@ -3824,6 +3826,8 @@ val split_str(val str, val sep) if (len) { pos = plus(pos, len); + if (keep_sep) + iter = list_collect(iter, sub_str(str, new_pos, pos)); continue; } break; @@ -3846,6 +3850,8 @@ val split_str(val str, val sep) val piece = mkustring(one); init_str(piece, cstr); iter = list_collect(iter, piece); + if (keep_sep && *(cstr+1)) + iter = list_collect(iter, null_string); } gc_hint(str); @@ -3870,6 +3876,8 @@ val split_str(val str, val sep) cstr += span; if (psep != 0) { cstr += len_sep; + if (keep_sep) + iter = list_collect(iter, sep); continue; } break; @@ -3883,6 +3891,11 @@ val split_str(val str, val sep) } } +val split_str(val str, val sep) +{ + return split_str_keep(str, sep, nil); +} + val split_str_set(val str, val set) { const wchar_t *cstr = c_str(str); |