From a2e0d566ef4d45d4915d43d035f6f21270d70178 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 17 Aug 2022 07:07:41 -0700 Subject: New function: search-all * eval.c (eval_init): search-all intrinsic registered. * lib.c (search_common): New Boolean argument all, indicating whether all positions are to be returned. We must handle this in the two places where empty key and sequence are handled, and also in the main loop. A trick is used: the found variable is now bound by list_collect_decl, but not used for collecting unless all is true. (search, rsearch, contains): Pass 0 for all argument of search_common. (search_all): New function. * lib.h (search_all): Declared. * tests/012/seq.tl: New tests. * txr.1: Documented. * stdlib/doc-syms.tl: Regenerated. --- tests/012/seq.tl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/012') diff --git a/tests/012/seq.tl b/tests/012/seq.tl index 4a1be8dd..a65d8ffa 100644 --- a/tests/012/seq.tl +++ b/tests/012/seq.tl @@ -501,6 +501,7 @@ [count #1="abc" '("abc" "abc" "abc" #1# "abc" #1#" abc") eq] 2)) (mtest + (search "" "") 0 (search "abcde" "ab") 0 (search "abcde" "bc") 1 (search "abcde" "cd") 2 @@ -510,6 +511,7 @@ (search "abcde" "x") nil) (mtest + (search nil nil) 0 (search '#"a b c d e" '#"a b") 0 (search '#"a b c d e" '#"b c") 1 (search '#"a b c d e" '#"c d") 2 @@ -519,6 +521,7 @@ (search '#"a b c d e" '#"x") nil) (mtest + (rsearch nil nil) 0 (rsearch "abcde" "ab") 0 (rsearch "abcde" "bc") 1 (rsearch "abcde" "cd") 2 @@ -535,3 +538,15 @@ (rsearch '#"a b c d e" '#"e") 4 (rsearch '#"a b c d e" nil) 5 (rsearch '#"a b c d e" '#"x") nil) + +(mtest + (search-all "" "") (0) + (search-all "xxxxx" "y") nil + (search-all "xxxxx" "x") (0 1 2 3 4) + (search-all "xxx" "") (0 1 2 3)) + +(mtest + (search-all nil nil) (0) + (search-all '#"x x x x x" '#"y") nil + (search-all '#"x x x x x" '#"x") (0 1 2 3 4) + (search-all '#"x x x" "") (0 1 2 3)) -- cgit v1.2.3