@@ -85,6 +85,29 @@ void strvec_split(struct strvec *array, const char *to_split)
}
}
+size_t strvec_split_delim(struct strvec *array, const char *string,
+ int delim, int maxsplit)
+{
+ size_t count = 0;
+ const char *p = string, *end;
+
+ for (;;) {
+ count++;
+ if (maxsplit >= 0 && count > maxsplit) {
+ strvec_push(array, p);
+ return count;
+ }
+ end = strchr(p, delim);
+ if (end) {
+ strvec_push_nodup(array, xmemdupz(p, end - p));
+ p = end + 1;
+ } else {
+ strvec_push(array, p);
+ return count;
+ }
+ }
+}
+
void strvec_clear(struct strvec *array)
{
if (array->v != empty_strvec) {
@@ -73,6 +73,14 @@ void strvec_pop(struct strvec *);
/* Splits by whitespace; does not handle quoted arguments! */
void strvec_split(struct strvec *, const char *);
+/**
+ * strvec_split_delim() is a split function that behaves more like its
+ * string_list_split() cousin than the whitespace-splitting
+ * strvec_split().
+ */
+size_t strvec_split_delim(struct strvec *array, const char *string,
+ int delim, int maxsplit);
+
/**
* Free all memory associated with the array and return it to the
* initial, empty state.