string-list: optionally trim string pieces split by string_list_split*()

Teach the unified split_string() to take an optional "flags" word,
and define the first flag STRING_LIST_SPLIT_TRIM to cause the split
pieces to be trimmed before they are placed in the string list.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano
2025-08-01 15:04:20 -07:00
parent 527535fcdd
commit 5764549741
3 changed files with 109 additions and 5 deletions

View File

@@ -281,4 +281,19 @@ 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);
/* Flag bits for split_f and split_in_place_f functions */
enum {
/*
* trim whitespaces around resulting string piece before adding
* it to the list
*/
STRING_LIST_SPLIT_TRIM = (1 << 0),
};
int string_list_split_f(struct string_list *, const char *string,
const char *delim, int maxsplit, unsigned flags);
int string_list_split_in_place_f(struct string_list *, char *string,
const char *delim, int maxsplit, unsigned flags);
#endif /* STRING_LIST_H */