Re: [PATCH v2 4/7] string-list: optionally trim string pieces split by string_list_split*()
- From
shejialuo <shejialuo@gmail.com>
- Date
- Aug 1, 2025, 03:18 UTC
- Message-ID
- <aIwyIJqEIdSdKINz@mbp>
- In-Reply-To
- <20250731224607.3942417-5-gitster@pobox.com>
On Thu, Jul 31, 2025 at 03:46:03PM -0700, Junio C Hamano wrote:
Show 21 quoted lines
> static int split_string(struct string_list *list, const char *string, const char *delim,
> - int maxsplit, int in_place)
> + int maxsplit, int in_place, unsigned flags)
> {
> int count = 0;
> const char *p = string;
> @@ -320,12 +327,18 @@ static int split_string(struct string_list *list, const char *string, const char
> for (;;) {
> char *end;
>
> + if (flags & STRING_LIST_SPLIT_TRIM) {
> + /* ltrim */
> + while (*p && isspace(*p))
> + p++;
> + }
> +
> if (0 <= maxsplit && maxsplit <= count)
> end = NULL;
> else
> end = strpbrk(p, delim);
> In `append_one`, we would tell whether `end` is NULL. I somehow feel strange why we need to do that in `append_one`. Should we just set `end` to be `p + strlen(p)` when `end` is NULL. And then we could do rtrim inside this function instead of `append_one` to avoid passing "flags" to `append_one`.
Show 5 quoted lines
> - count += append_one(list, p, end, in_place); > + count += append_one(list, p, end, in_place, flags); > > if (!end) > return count;
Thanks, Jialuo