From 28c6225fec6ce999806e9c077f08ed0e668646c4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 14 Jun 2019 20:00:48 -0700 Subject: cat-str, split-str: sep can be character. * lib.c (cat_str, split_str_keep): Support single character separator. * txr.1: Documented. --- lib.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'lib.c') diff --git a/lib.c b/lib.c index e3f63386..de78d8a9 100644 --- a/lib.c +++ b/lib.c @@ -3845,7 +3845,18 @@ val cat_str(val list, val sep) cnum total = 0; val iter; wchar_t *str, *ptr; - cnum len_sep = (!null_or_missing_p(sep)) ? c_num(length_str(sep)) : 0; + wchar_t onech[] = wini(" "); + cnum len_sep; + + if (null_or_missing_p(sep)) { + len_sep = 0; + } else if (chrp(sep)) { + onech[0] = c_chr(sep); + len_sep = 1; + sep = auto_str(coerce(const wchli_t *, wref(onech))); + } else { + len_sep = c_num(length_str(sep)); + } for (iter = list; iter != nil; iter = cdr(iter)) { val item = car(iter); @@ -4018,7 +4029,16 @@ val split_str_keep(val str, val sep, val keep_sep) return out; } else { - size_t len_sep = c_num(length_str(sep)); + size_t len_sep; + wchar_t onech[] = wini(" "); + + if (chrp(sep)) { + onech[0] = c_chr(sep); + len_sep = 1; + sep = auto_str(coerce(const wchli_t *, wref(onech))); + } else { + len_sep = c_num(length_str(sep)); + } if (len_sep == 0) { if (opt_compat && opt_compat <= 100) { -- cgit v1.2.3