Re: [PATCH v2 1/6] string-list: introduce `string_list_split_in_place_multi()`
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 18, 2023, 19:39 UTC
- Message-ID
- <xmqqleipc73v.fsf@gitster.g>
- In-Reply-To
- <6658b231a906dde6acbe7ce156da693ef7dc40e6.1681845518.git.me@ttaylorr.com>
Taylor Blau <me@ttaylorr.com> writes:
Show 14 quoted lines
> Introduce a variant of the `string_list_split_in_place()` function that
> takes a string of accepted delimiters.
>
> By contrast to its cousin `string_list_split_in_place()` which splits
> the given string at every instance of the single character `delim`, the
> `_multi` variant splits the given string any any character appearing in
> the string `delim`.
>
> Like `strtok()`, the `_multi` variant skips past sequential delimiting
> characters. For example:
>
> string_list_split_in_place(&xs, xstrdup("foo::bar::baz"), ":", -1);
>
> would place in `xs` the elements "foo", "bar", and "baz".strtok() also skips leading and trailing delimiters, i.e. the above will give you identical result for ":foo:bar:baz:".
It would be useful to test that here in addition to the existing ones.
Show 26 quoted lines
> +for test_fn in test_split test_split_in_place_multi > +do > + $test_fn "foo:bar:baz" ":" "-1" <<-\EOF > + 3 > + [0]: "foo" > + [1]: "bar" > + [2]: "baz" > + EOF > > + $test_fn "foo:bar:baz" ":" "0" <<-\EOF > + 1 > + [0]: "foo:bar:baz" > + EOF > > + $test_fn "foo:bar:baz" ":" "1" <<-\EOF > + 2 > + [0]: "foo" > + [1]: "bar:baz" > + EOF > > + $test_fn "foo:bar:baz" ":" "2" <<-\EOF > + 3 > + [0]: "foo" > + [1]: "bar" > + [2]: "baz" > + EOF