diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-09-05 12:06:53 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-09-05 12:06:53 +0200 |
commit | 5cdddd32ef3df78be7cb187446235a04491036b5 (patch) | |
tree | a0b81ae65dcc4a9598ef3bf1ae4ba4c1bce01520 /tests/custom/03_stdlib/18_split | |
parent | 68b5a1eb5c8e35b9d299879df00b8130ce164cad (diff) |
lib: add limit support to split() and replace()
Extend the split() and replace() functions to accept an additional optional
`limit` argument which limits the amount of split operations / substitutions
performed by these functions.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/custom/03_stdlib/18_split')
-rw-r--r-- | tests/custom/03_stdlib/18_split | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/custom/03_stdlib/18_split b/tests/custom/03_stdlib/18_split index 5ee35a2..20d5c8d 100644 --- a/tests/custom/03_stdlib/18_split +++ b/tests/custom/03_stdlib/18_split @@ -43,6 +43,18 @@ argument is neither a string nor a regular expression. // subject and split strings handle embedded \0 split("foo=1\0bar=2\0baz=3", "\0"), + + // supplying a limit only splits the string into that many parts + split("foo=1=2=3", "=", 2), + + // limit of one produces a result array conaining the entire string as sole item + split("foo=1=2=3", "=", 1), + + // negative limit yields an empty result array + split("foo=1=2=3", "=", -1), + + // zero limit yields an empty result array + split("foo=1=2=3", "=", 0), ]), "\n"); %} -- End -- @@ -62,6 +74,10 @@ argument is neither a string nor a regular expression. [ "", "abc", "def", "" ] [ "", "foo", "bar", "" ] [ "foo=1", "bar=2", "baz=3" ] +[ "foo", "1=2=3" ] +[ "foo=1=2=3" ] +[ ] +[ ] -- End -- |