summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-06-14 20:00:48 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-06-14 20:00:48 -0700
commit28c6225fec6ce999806e9c077f08ed0e668646c4 (patch)
tree653d4b5c57e9eef7d37bd5fc06b2a5cfc83ff3ad /lib.c
parentdc0f9b2d38c58f7058d44e07ae04fde94356473b (diff)
downloadtxr-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.c24
1 files changed, 22 insertions, 2 deletions
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) {