Re: [PATCH v2 4/7] string-list: optionally trim string pieces split by string_list_split*()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jul 31, 2025 at 03:46:03PM -0700, Junio C Hamano wrote:
> 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.

> 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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux