summaryrefslogtreecommitdiff
path: root/argv-array.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2018-04-25 11:53:57 +0200
committerJunio C Hamano <gitster@pobox.com>2018-04-26 12:52:57 +0900
commitc5aa6db64f6f43621568bb1fec9360c25dbd2749 (patch)
tree1fbcdaab2c2e157afbe8def43d47b1b432463a7b /argv-array.c
parent1f1cddd558b54bb0ce19c8ace353fd07b758510d (diff)
downloadgit-c5aa6db64f6f43621568bb1fec9360c25dbd2749.tar.gz
argv_array: offer to split a string by whitespace
This is a simple function that will interpret a string as a whitespace delimited list of values, and add those values into the array. Note: this function does not (yet) offer to split by arbitrary delimiters, or keep empty values in case of runs of whitespace, or de-quote Unix shell style. All fo this functionality can be added later, when and if needed. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'argv-array.c')
-rw-r--r--argv-array.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/argv-array.c b/argv-array.c
index 5d370fa336..cb5bcd2c06 100644
--- a/argv-array.c
+++ b/argv-array.c
@@ -64,6 +64,26 @@ void argv_array_pop(struct argv_array *array)
array->argc--;
}
+void argv_array_split(struct argv_array *array, const char *to_split)
+{
+ while (isspace(*to_split))
+ to_split++;
+ for (;;) {
+ const char *p = to_split;
+
+ if (!*p)
+ break;
+
+ while (*p && !isspace(*p))
+ p++;
+ argv_array_push_nodup(array, xstrndup(to_split, p - to_split));
+
+ while (isspace(*p))
+ p++;
+ to_split = p;
+ }
+}
+
void argv_array_clear(struct argv_array *array)
{
if (array->argv != empty_argv) {