diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-06-14 20:00:48 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-06-14 20:00:48 -0700 |
commit | 28c6225fec6ce999806e9c077f08ed0e668646c4 (patch) | |
tree | 653d4b5c57e9eef7d37bd5fc06b2a5cfc83ff3ad /lib.c | |
parent | dc0f9b2d38c58f7058d44e07ae04fde94356473b (diff) | |
download | txr-28c6225fec6ce999806e9c077f08ed0e668646c4.tar.gz txr-28c6225fec6ce999806e9c077f08ed0e668646c4.tar.bz2 txr-28c6225fec6ce999806e9c077f08ed0e668646c4.zip |
cat-str, split-str: sep can be character.
* lib.c (cat_str, split_str_keep): Support single character
separator.
* txr.1: Documented.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 24 |
1 files changed, 22 insertions, 2 deletions
@@ -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) { |