summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 89fbda2)
raw | patch | inline | side by side (parent: 89fbda2)
author | Christian Couder <chriscool@tuxfamily.org> | |
Sun, 29 Mar 2009 09:44:44 +0000 (11:44 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 30 Mar 2009 08:22:53 +0000 (01:22 -0700) |
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>
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>
quote.c | patch | blob | history | |
quote.h | patch | blob | history |
index 6a520855d6c418ecb1384ef9571b122b134af1af..ea49c7a99fb1fc28f786d53f528addf4dcbf5a02 100644 (file)
--- a/quote.c
+++ b/quote.c
}
}
-char *sq_dequote(char *arg)
+char *sq_dequote_step(char *arg, char **next)
{
char *dst = arg;
char *src = arg;
switch (*++src) {
case '\0':
*dst = 0;
+ if (next)
+ *next = NULL;
return arg;
case '\\':
c = *++src;
}
/* 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
index c5eea6f18e2dfabd071b73e6507c34c2b7b5e39f..2315105fa3eae59f6abaf636eec7590c335154b4 100644 (file)
--- a/quote.h
+++ b/quote.h
*/
extern char *sq_dequote(char *);
+/*
+ * Same as the above, but can be used to unwrap many arguments in the
+ * same string separated by space. "next" is changed to point to the
+ * next argument that should be passed as first parameter. When there
+ * is no more argument to be dequoted, "next" is updated to point to NULL.
+ */
+extern char *sq_dequote_step(char *arg, char **next);
+
extern int unquote_c_style(struct strbuf *, const char *quoted, const char **endp);
extern size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq);
extern void quote_two_c_style(struct strbuf *, const char *, const char *, int);