diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-10-25 18:39:58 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-10-25 18:39:58 -0700 |
commit | af623d27b590f3596b219c9be2faa1853f8d9db4 (patch) | |
tree | b81451c9d82aaaef211b605571127ce1e9e2bac1 /tests/015 | |
parent | 8357dd0ce75b5cace504acfcef2c31ee83a35e9c (diff) | |
download | txr-af623d27b590f3596b219c9be2faa1853f8d9db4.tar.gz txr-af623d27b590f3596b219c9be2faa1853f8d9db4.tar.bz2 txr-af623d27b590f3596b219c9be2faa1853f8d9db4.zip |
cat-str/join/join-with: allow nested sequences
The measure/allocate/catenate functions which underlie
the cat-str implementation are streamlined, simplifying
the code. At the same time, they handle nested sequences
of string/character items.
* lib.c (struct cat_str): New member, seen_one. This flips
from 0 to 1 after the first item has been seen in the
cat_str_measure pass or cat_str_append pass. Each item
other than the first is preceded by a separator.
(cat_str_measure, cat_str_append): The more_p argument
is dropped. We account for the separator with the help
of the new seen_one flag, which allows us to easily
recurse over items that are sequences.
(cat_str_alloc): Reset the seen_one flag in preparation
for the cat_str_append pass.
(cat_str, vscat, scat2, scat3, join_with): Simplified.
* tests/015/split.tl: New tests.
* txr.1: Redocumented.
Diffstat (limited to 'tests/015')
-rw-r--r-- | tests/015/split.tl | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/015/split.tl b/tests/015/split.tl index 15b3f2a7..1cb13647 100644 --- a/tests/015/split.tl +++ b/tests/015/split.tl @@ -298,3 +298,16 @@ (spln 2 "," "a,b,c") ("a" "b" "c") (spln 3 "," "a,b,c") ("a" "b" "c") (spln 4 "," "a,b,c") ("a" "b" "c")) + +(mtest + (cat-str '()) "" + (cat-str '() "-") "" + (cat-str '(()) "-") "" + (cat-str '((()) ()) "-") "" + (cat-str '((()) #()) "-") "" + (cat-str '((("a" ("b")) #(#\c))) "-") "a-b-c") + +(mtest + (join-with "--" '()) "" + (join-with "--" '(("b"))) "b" + (join-with "--" '("b" #(("c") ()) "d")) "b--c--d") |