colorfield_nr = 0;
/* Ideally this would be stripped and split at the same time? */
- string_list_split(&l, s, ',', -1);
+ string_list_split(&l, s, ",", -1);
ALLOC_GROW(colorfield, colorfield_nr + 1, colorfield_alloc);
for_each_string_list_item(item, &l) {
if (string) {
struct string_list list = STRING_LIST_INIT_DUP;
struct string_list_item *item;
- string_list_split(&list, string, ' ', -1);
+ string_list_split(&list, string, " ", -1);
for_each_string_list_item(item, &list)
append_strategy(get_strategy(item->string));
string_list_clear(&list, 0);
if (ptr->multivalued && *val) {
struct string_list list = STRING_LIST_INIT_DUP;
- string_list_split(&list, val, '\n', -1);
+ string_list_split(&list, val, "\n", -1);
for (size_t i = 0; i < list.nr; i++)
printf("%s=%s\n", ptr->name, list.items[i].string);
string_list_clear(&list, 0);
* name. Subsequent fields (symref-target and peeled) are optional and
* don't have a particular order.
*/
- if (string_list_split(&line_sections, line, ' ', -1) < 2) {
+ if (string_list_split(&line_sections, line, " ", -1) < 2) {
ret = 0;
goto out;
}
struct string_list l = STRING_LIST_INIT_DUP;
struct string_list_item *i;
- string_list_split(&l, arg, ',', -1);
+ string_list_split(&l, arg, ",", -1);
for_each_string_list_item(i, &l) {
struct strbuf sb = STRBUF_INIT;
char *str;
if (!git_config_get_string("fetch.uriprotocols", &str) && str) {
- string_list_split(&uri_protocols, str, ',', -1);
+ string_list_split(&uri_protocols, str, ",", -1);
free(str);
}
}
* later, along with any empty strings that came from empty
* lines within the file.
*/
- string_list_split(list, data, '\n', -1);
+ string_list_split(list, data, "\n", -1);
free(data);
return 0;
}
if (!saw_empty_line && !*str)
saw_empty_line = 1;
- string_list_split(&list, str, '\n', -1);
+ string_list_split(&list, str, "\n", -1);
for (j = 0; j < list.nr; j++) {
const char *line = list.items[j].string;
if (!value || !*value)
die(_("attr spec must not be empty"));
- string_list_split(&list, value, ' ', -1);
+ string_list_split(&list, value, " ", -1);
string_list_remove_empty_items(&list, 0);
item->attr_check = attr_check_alloc();
if (git_protocol) {
struct string_list list = STRING_LIST_INIT_DUP;
const struct string_list_item *item;
- string_list_split(&list, git_protocol, ':', -1);
+ string_list_split(&list, git_protocol, ":", -1);
for_each_string_list_item(item, &list) {
const char *value;
}
atom->u.remote_ref.nobracket = 0;
- string_list_split(¶ms, arg, ',', -1);
+ string_list_split(¶ms, arg, ",", -1);
for (i = 0; i < params.nr; i++) {
const char *s = params.items[i].string;
align->position = ALIGN_LEFT;
- string_list_split(¶ms, arg, ',', -1);
+ string_list_split(¶ms, arg, ",", -1);
for (i = 0; i < params.nr; i++) {
const char *s = params.items[i].string;
int position;
if (env_ceiling_dirs) {
int empty_entry_found = 0;
+ static const char path_sep[] = { PATH_SEP, '\0' };
- string_list_split(&ceiling_dirs, env_ceiling_dirs, PATH_SEP, -1);
+ string_list_split(&ceiling_dirs, env_ceiling_dirs, path_sep, -1);
filter_string_list(&ceiling_dirs, 0,
canonicalize_ceiling_entry, &empty_entry_found);
ceil_offset = longest_ancestor_length(dir->buf, &ceiling_dirs);
}
int string_list_split(struct string_list *list, const char *string,
- int delim, int maxsplit)
+ const char *delim, int maxsplit)
{
int count = 0;
const char *p = string, *end;
string_list_append(list, p);
return count;
}
- end = strchr(p, delim);
+ end = strpbrk(p, delim);
if (end) {
string_list_append_nodup(list, xmemdupz(p, end - p));
p = end + 1;
void unsorted_string_list_delete_item(struct string_list *list, int i, int free_util);
/**
- * Split string into substrings on character `delim` and append the
+ * Split string into substrings on characters in `delim` and append the
* substrings to `list`. The input string is not modified.
* list->strdup_strings must be set, as new memory needs to be
* allocated to hold the substrings. If maxsplit is non-negative,
* appended to list.
*
* Examples:
- * string_list_split(l, "foo:bar:baz", ':', -1) -> ["foo", "bar", "baz"]
- * string_list_split(l, "foo:bar:baz", ':', 0) -> ["foo:bar:baz"]
- * string_list_split(l, "foo:bar:baz", ':', 1) -> ["foo", "bar:baz"]
- * string_list_split(l, "foo:bar:", ':', -1) -> ["foo", "bar", ""]
- * string_list_split(l, "", ':', -1) -> [""]
- * string_list_split(l, ":", ':', -1) -> ["", ""]
+ * string_list_split(l, "foo:bar:baz", ":", -1) -> ["foo", "bar", "baz"]
+ * string_list_split(l, "foo:bar:baz", ":", 0) -> ["foo:bar:baz"]
+ * string_list_split(l, "foo:bar:baz", ":", 1) -> ["foo", "bar:baz"]
+ * string_list_split(l, "foo:bar:", ":", -1) -> ["foo", "bar", ""]
+ * string_list_split(l, "", ":", -1) -> [""]
+ * string_list_split(l, ":", ":", -1) -> ["", ""]
*/
int string_list_split(struct string_list *list, const char *string,
- int delim, int maxsplit);
+ const char *delim, int maxsplit);
/*
* Like string_list_split(), except that string is split in-place: the
if (argc == 4 && !strcmp(argv[1], "longest_ancestor_length")) {
int len;
struct string_list ceiling_dirs = STRING_LIST_INIT_DUP;
+ const char path_sep[] = { PATH_SEP, '\0' };
char *path = xstrdup(argv[2]);
/*
*/
if (normalize_path_copy(path, path))
die("Path \"%s\" could not be normalized", argv[2]);
- string_list_split(&ceiling_dirs, argv[3], PATH_SEP, -1);
+ string_list_split(&ceiling_dirs, argv[3], path_sep, -1);
filter_string_list(&ceiling_dirs, 0,
normalize_ceiling_entry, NULL);
len = longest_ancestor_length(path, &ceiling_dirs);
if (!strcmp(str, "0"))
return 0;
- string_list_split(&masks, str, ',', 64);
+ string_list_split(&masks, str, ",", 64);
for (size_t i = 0; i < masks.nr; i++) {
const char *name = masks.items[i].string;
struct flag_definition *def = defs;
expected_strings->items[i].string);
}
-static void t_string_list_split(const char *data, int delim, int maxsplit, ...)
+static void t_string_list_split(const char *data, const char *delim, int maxsplit, ...)
{
struct string_list expected_strings = STRING_LIST_INIT_DUP;
struct string_list list = STRING_LIST_INIT_DUP;
void test_string_list__split(void)
{
- t_string_list_split("foo:bar:baz", ':', -1, "foo", "bar", "baz", NULL);
- t_string_list_split("foo:bar:baz", ':', 0, "foo:bar:baz", NULL);
- t_string_list_split("foo:bar:baz", ':', 1, "foo", "bar:baz", NULL);
- t_string_list_split("foo:bar:baz", ':', 2, "foo", "bar", "baz", NULL);
- t_string_list_split("foo:bar:", ':', -1, "foo", "bar", "", NULL);
- t_string_list_split("", ':', -1, "", NULL);
- t_string_list_split(":", ':', -1, "", "", NULL);
+ t_string_list_split("foo:bar:baz", ":", -1, "foo", "bar", "baz", NULL);
+ t_string_list_split("foo:bar:baz", ":", 0, "foo:bar:baz", NULL);
+ t_string_list_split("foo:bar:baz", ":", 1, "foo", "bar:baz", NULL);
+ t_string_list_split("foo:bar:baz", ":", 2, "foo", "bar", "baz", NULL);
+ t_string_list_split("foo:bar:", ":", -1, "foo", "bar", "", NULL);
+ t_string_list_split("", ":", -1, "", NULL);
+ t_string_list_split(":", ":", -1, "", "", NULL);
}
static void t_string_list_split_in_place(const char *data, const char *delim,
if (enabled < 0) {
const char *v = getenv("GIT_ALLOW_PROTOCOL");
if (v) {
- string_list_split(&allowed, v, ':', -1);
+ string_list_split(&allowed, v, ":", -1);
string_list_sort(&allowed);
enabled = 1;
} else {
if (data->uri_protocols.nr)
send_err_and_die(data,
"multiple packfile-uris lines forbidden");
- string_list_split(&data->uri_protocols, p, ',', -1);
+ string_list_split(&data->uri_protocols, p, ",", -1);
continue;
}