diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-05-30 06:44:28 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-05-30 06:44:28 -0700 |
commit | cce3c4bef38888be015b0652d136e34c8ae7e59f (patch) | |
tree | 8f1af5da0718bf01b71ca860616ca7b8f3d652a6 /lib.c | |
parent | bc591cb5ee04582dbdf17a0125987ec03e8c064f (diff) | |
download | txr-cce3c4bef38888be015b0652d136e34c8ae7e59f.tar.gz txr-cce3c4bef38888be015b0652d136e34c8ae7e59f.tar.bz2 txr-cce3c4bef38888be015b0652d136e34c8ae7e59f.zip |
New: spln and tokn functions.
Instead of trying to work the new count parameter into the spl and
tok functions, it's better to make new ones.
* eval.c (eval_init): spln and tokn intrinsics registered.
* lib.[ch] (spln, tokn): New functions.
* tests/015/split.tl: New test cases.
* txr.1: Documented.
* stdlib/doc-syms.tl: Updated.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -5859,6 +5859,18 @@ val spl(val sep, val arg1, val arg2) split_str_keep(arg2, sep, arg1, nil)); } +val spln(val count, val sep, val arg1, val arg2) +{ + val self = lit("spln"); + + if (null_or_missing_p(count)) + uw_throwf(error_s, lit("~a: count ~s isn't an integer"), self, count, nao); + + return if3(missingp(arg2), + split_str_keep(arg1, sep, arg2, count), + split_str_keep(arg2, sep, arg1, count)); +} + val split_str(val str, val sep) { return split_str_keep(str, sep, nil, nil); @@ -5977,6 +5989,18 @@ val tok(val tok_regex, val arg1, val arg2) tok_str(arg2, tok_regex, arg1, nil)); } +val tokn(val count, val tok_regex, val arg1, val arg2) +{ + val self = lit("tokn"); + + if (null_or_missing_p(count)) + uw_throwf(error_s, lit("~a: count ~s isn't an integer"), self, count, nao); + + return if3(missingp(arg2), + tok_str(arg1, tok_regex, arg2, count), + tok_str(arg2, tok_regex, arg1, count)); +} + val tok_where(val str, val tok_regex) { list_collect_decl (out, iter); |