Re: [PATCH v2 4/7] string-list: optionally trim string pieces split by string_list_split*()
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Aug 1, 2025, 08:47 UTC
- Message-ID
- <aIx_HIjWEDx9pNW2@pks.im>
- In-Reply-To
- <20250731224607.3942417-5-gitster@pobox.com>
On Thu, Jul 31, 2025 at 03:46:03PM -0700, Junio C Hamano wrote:
Show 30 quoted lines
> diff --git a/string-list.c b/string-list.c
> index 65b6ceb259..86a309f8fb 100644
> --- a/string-list.c
> +++ b/string-list.c
> @@ -336,11 +349,23 @@ static int split_string(struct string_list *list, const char *string, const char
> int string_list_split(struct string_list *list, const char *string,
> const char *delim, int maxsplit)
> {
> - return split_string(list, string, delim, maxsplit, 0);
> + return split_string(list, string, delim, maxsplit, 0, 0);
> }
>
> int string_list_split_in_place(struct string_list *list, char *string,
> const char *delim, int maxsplit)
> {
> - return split_string(list, string, delim, maxsplit, 1);
> + return split_string(list, string, delim, maxsplit, 1, 0);
> +}
> +
> +int string_list_split_f(struct string_list *list, const char *string,
> + const char *delim, int maxsplit, unsigned flags)
> +{
> + return split_string(list, string, delim, maxsplit, 0, flags);
> +}
> +
> +int string_list_split_in_place_f(struct string_list *list, char *string,
> + const char *delim, int maxsplit, unsigned flags)
> +{
> + return split_string(list, string, delim, maxsplit, 1, flags);
> }One issue I have with the `_f` suffix is that I immediately jumped to "formatting string". I think in other places we use `_ext` as a suffix.
Show 11 quoted lines
> diff --git a/string-list.h b/string-list.h > index 6c8650efde..ee9922af67 100644 > --- a/string-list.h > +++ b/string-list.h > @@ -281,4 +281,14 @@ int string_list_split(struct string_list *list, const char *string, > */ > int string_list_split_in_place(struct string_list *list, char *string, > const char *delim, int maxsplit); > + > +/* trim() resulting string piece before adding it to the list */ > +#define STRING_LIST_SPLIT_TRIM 01
Another nit: I think nowadays we more often use enums to introduce such flags, where the benefit is improved grouping. Also, I think having `(1 << 0)` as value is slightly more readable.
Patrick