diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-03-31 23:52:30 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-03-31 23:52:30 -0700 |
commit | a7029badeda2a898a3a1e7fade1246fd454ba66e (patch) | |
tree | 4a868b08603ecad043ad722694f5addac77ff4dd /testcases-iter | |
parent | a3587e13398f6ce2197e8d728f52f8389d4ffdec (diff) | |
download | cppawk-a7029badeda2a898a3a1e7fade1246fd454ba66e.tar.gz cppawk-a7029badeda2a898a3a1e7fade1246fd454ba66e.tar.bz2 cppawk-a7029badeda2a898a3a1e7fade1246fd454ba66e.zip |
loop: new clauses first_then, for_var, collect_plus.
Diffstat (limited to 'testcases-iter')
-rw-r--r-- | testcases-iter | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/testcases-iter b/testcases-iter index b9b7d22..629420e 100644 --- a/testcases-iter +++ b/testcases-iter @@ -332,3 +332,39 @@ BEGIN { }' : min = -3 +-- +16: +$cppawk ' +#include <iter.h> + + +function index_from(str, ch, start, + sstr, pos) +{ + sstr = substr(str, start) + pos = index(sstr, ch) + return pos ? pos + start - 1 : 0 +} + +function sscl(string, char) +{ + loop (first_then (start, 1, end + 1), + for_var (end, index_from(string, char, start)), + collect_plus (out, end ? substr(string, start, end - start) + : substr(string, start)), + while (end)) + { } + return out +} + +BEGIN { + print sexp(sscl(",", ",")) + print sexp(sscl("a,", ",")) + print sexp(sscl(",a", ",")) + print sexp(sscl("a,b,c", ",")) +}' +: +(nil nil) +("a" nil) +(nil "a") +("a" "b" "c") |