summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFilipe Brandenburger <filbranden@google.com>2015-05-29 23:42:47 -0700
committerFilipe Brandenburger <filbranden@google.com>2015-06-17 11:12:11 -0700
commit05654e712f0ccfea7bbeb3e4de89861a670f974e (patch)
treef7aeaa3e4badce5c2c4537532b0ec018c1e0b14a /src
parentb3d4ef81f6aaac3df8d15ad0d2e3f78b74c00d28 (diff)
util: Refactor common cunescape block in unquote_first_word
Diffstat (limited to 'src')
-rw-r--r--src/basic/util.c68
1 files changed, 7 insertions, 61 deletions
diff --git a/src/basic/util.c b/src/basic/util.c
index e0c5069ff8..e0d1220153 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -5209,35 +5209,6 @@ int unquote_first_word(const char **p, char **ret, UnquoteFlags flags) {
break;
- case VALUE_ESCAPE:
- if (c == 0) {
- if (flags & UNQUOTE_RELAX)
- goto finish;
- return -EINVAL;
- }
-
- if (!GREEDY_REALLOC(s, allocated, sz+7))
- return -ENOMEM;
-
- if (flags & UNQUOTE_CUNESCAPE) {
- uint32_t u;
-
- r = cunescape_one(*p, (size_t) -1, &c, &u);
- if (r < 0)
- return -EINVAL;
-
- (*p) += r - 1;
-
- if (c != 0)
- s[sz++] = c; /* normal explicit char */
- else
- sz += utf8_encode_unichar(s + sz, u); /* unicode chars we'll encode as utf8 */
- } else
- s[sz++] = c;
-
- state = VALUE;
- break;
-
case SINGLE_QUOTE:
if (c == 0) {
if (flags & UNQUOTE_RELAX)
@@ -5256,35 +5227,6 @@ int unquote_first_word(const char **p, char **ret, UnquoteFlags flags) {
break;
- case SINGLE_QUOTE_ESCAPE:
- if (c == 0) {
- if (flags & UNQUOTE_RELAX)
- goto finish;
- return -EINVAL;
- }
-
- if (!GREEDY_REALLOC(s, allocated, sz+7))
- return -ENOMEM;
-
- if (flags & UNQUOTE_CUNESCAPE) {
- uint32_t u;
-
- r = cunescape_one(*p, (size_t) -1, &c, &u);
- if (r < 0)
- return -EINVAL;
-
- (*p) += r - 1;
-
- if (c != 0)
- s[sz++] = c;
- else
- sz += utf8_encode_unichar(s + sz, u);
- } else
- s[sz++] = c;
-
- state = SINGLE_QUOTE;
- break;
-
case DOUBLE_QUOTE:
if (c == 0)
return -EINVAL;
@@ -5301,7 +5243,9 @@ int unquote_first_word(const char **p, char **ret, UnquoteFlags flags) {
break;
+ case SINGLE_QUOTE_ESCAPE:
case DOUBLE_QUOTE_ESCAPE:
+ case VALUE_ESCAPE:
if (c == 0) {
if (flags & UNQUOTE_RELAX)
goto finish;
@@ -5321,13 +5265,15 @@ int unquote_first_word(const char **p, char **ret, UnquoteFlags flags) {
(*p) += r - 1;
if (c != 0)
- s[sz++] = c;
+ s[sz++] = c; /* normal explicit char */
else
- sz += utf8_encode_unichar(s + sz, u);
+ sz += utf8_encode_unichar(s + sz, u); /* unicode chars we'll encode as utf8 */
} else
s[sz++] = c;
- state = DOUBLE_QUOTE;
+ state = (state == SINGLE_QUOTE_ESCAPE) ? SINGLE_QUOTE :
+ (state == DOUBLE_QUOTE_ESCAPE) ? DOUBLE_QUOTE :
+ VALUE;
break;
case SPACE: