summaryrefslogtreecommitdiff
path: root/quote.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2021-01-12 12:26:49 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-01-12 20:03:18 (GMT)
commit13c44953fb0b396d3594b4a712f956ab3a48169e (patch)
tree1f6c689e4bd4b6cd574b1ea767ed57119caca4ea /quote.c
parentce81b1da230cf04e231ce337c2946c0671ffb303 (diff)
downloadgit-13c44953fb0b396d3594b4a712f956ab3a48169e.zip
git-13c44953fb0b396d3594b4a712f956ab3a48169e.tar.gz
git-13c44953fb0b396d3594b4a712f956ab3a48169e.tar.bz2
quote: make sq_dequote_step() a public function
We provide a function for dequoting an entire string, as well as one for handling a space-separated list of quoted strings. But there's no way for a caller to parse a string like 'foo'='bar', even though it is easy to generate one using sq_quote_buf() or similar. Let's make the single-step function available to callers outside of quote.c. Note that we do need to adjust its implementation slightly: it insists on seeing whitespace between items, and we'd like to be more flexible than that. Since it only has a single caller, we can move that check (and slurping up any extra whitespace) into that caller. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'quote.c')
-rw-r--r--quote.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/quote.c b/quote.c
index 69f4ca4..8a3a5e3 100644
--- a/quote.c
+++ b/quote.c
@@ -116,7 +116,7 @@ void sq_append_quote_argv_pretty(struct strbuf *dst, const char **argv)
}
}
-static char *sq_dequote_step(char *arg, char **next)
+char *sq_dequote_step(char *arg, char **next)
{
char *dst = arg;
char *src = arg;
@@ -153,11 +153,8 @@ static char *sq_dequote_step(char *arg, char **next)
}
/* Fallthrough */
default:
- if (!next || !isspace(*src))
+ if (!next)
return NULL;
- do {
- c = *++src;
- } while (isspace(c));
*dst = 0;
*next = src;
return arg;
@@ -182,6 +179,14 @@ static int sq_dequote_to_argv_internal(char *arg,
char *dequoted = sq_dequote_step(next, &next);
if (!dequoted)
return -1;
+ if (next) {
+ char c;
+ if (!isspace(*next))
+ return -1;
+ do {
+ c = *++next;
+ } while (isspace(c));
+ }
if (argv) {
ALLOC_GROW(*argv, *nr + 1, *alloc);
(*argv)[(*nr)++] = dequoted;