From 785087aa43cf962855724b8fa5da393022204a14 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 29 Sep 2022 13:12:19 +0200 Subject: Add $find(, ), $find_index(, ) functions The $find() function returns true if the sequence contains the specified value. The $find_index() function returns the index of the first element in the sequence that is equal to the specified value or $size() if none is found. For string sequences, it's possible to request case- insensitive comparison with a flag. --- tests/function/string/testscript | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/function/string/testscript') diff --git a/tests/function/string/testscript b/tests/function/string/testscript index 00835ce..364ce42 100644 --- a/tests/function/string/testscript +++ b/tests/function/string/testscript @@ -46,3 +46,19 @@ $* <'print $size([string] abc)' >'3' : basics $* <'print $size([string] )' >'0' : zero } + +: find +: +{ + $* <'print $find([strings] x y z, y)' >'true' : basics-true + $* <'print $find([strings] x y z, Y)' >'false' : basics-false + $* <'print $find([strings] x y z, Y, icase)' >'true' : icase +} + +: find_index +: +{ + $* <'print $find_index([strings] x y z, y)' >'1' : basics-true + $* <'print $find_index([strings] x y z, Y)' >'3' : basics-false + $* <'print $find_index([strings] x y z, Y, icase)' >'1' : icase +} -- cgit v1.1