summaryrefslogtreecommitdiff
path: root/string-list.h
diff options
context:
space:
mode:
Diffstat (limited to 'string-list.h')
-rw-r--r--string-list.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/string-list.h b/string-list.h
index 1b3915b..dc5fbc8 100644
--- a/string-list.h
+++ b/string-list.h
@@ -63,4 +63,33 @@ struct string_list_item *unsorted_string_list_lookup(struct string_list *list,
const char *string);
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
+ * 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,
+ * then split at most maxsplit times. Return the number of substrings
+ * 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) -> ["", ""]
+ */
+int string_list_split(struct string_list *list, const char *string,
+ int delim, int maxsplit);
+
+/*
+ * Like string_list_split(), except that string is split in-place: the
+ * delimiter characters in string are overwritten with NULs, and the
+ * new string_list_items point into string (which therefore must not
+ * be modified or freed while the string_list is in use).
+ * list->strdup_strings must *not* be set.
+ */
+int string_list_split_in_place(struct string_list *list, char *string,
+ int delim, int maxsplit);
#endif /* STRING_LIST_H */