diff options
author | Christian Couder <chriscool@tuxfamily.org> | 2009-03-29 11:44:44 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-03-30 01:22:53 -0700 |
commit | ebbc088e13e1bf0dbf8eb08b00519602c176f864 (patch) | |
tree | 95af836ac5362c32303967cc733b93c228691562 /quote.c | |
parent | 89fbda24256157cc43848488429fd20cf3bb21ab (diff) | |
download | git-ebbc088e13e1bf0dbf8eb08b00519602c176f864.tar.gz |
quote: implement "sq_dequote_many" to unwrap many args in one string
The sq_dequote() function does not allow parsing a string with more than
one single-quoted parameter easily; use its code to implement a new API
sq_dequote_step() to allow the caller iterate through such a string to
parse them one-by-one. The original sq_dequote() becomes a thin wrapper
around it.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'quote.c')
-rw-r--r-- | quote.c | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -72,7 +72,7 @@ void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen) } } -char *sq_dequote(char *arg) +char *sq_dequote_step(char *arg, char **next) { char *dst = arg; char *src = arg; @@ -92,6 +92,8 @@ char *sq_dequote(char *arg) switch (*++src) { case '\0': *dst = 0; + if (next) + *next = NULL; return arg; case '\\': c = *++src; @@ -101,11 +103,23 @@ char *sq_dequote(char *arg) } /* Fallthrough */ default: - return NULL; + if (!next || !isspace(*src)) + return NULL; + do { + c = *++src; + } while (isspace(c)); + *dst = 0; + *next = src; + return arg; } } } +char *sq_dequote(char *arg) +{ + return sq_dequote_step(arg, NULL); +} + /* 1 means: quote as octal * 0 means: quote as octal if (quote_path_fully) * -1 means: never quote |