]> git.kaiwu.me - klib.git/commitdiff
support single-quotation mark and escaping
authorHeng Li <lh3@me.com>
Fri, 22 May 2015 02:29:24 +0000 (22:29 -0400)
committerHeng Li <lh3@me.com>
Fri, 22 May 2015 02:29:24 +0000 (22:29 -0400)
kexpr.c

diff --git a/kexpr.c b/kexpr.c
index b897b8ccd131ce86ece0e64186fbb9cbe4d9c733..e94f7db6a42b6000c1de5ff233ee0e7ac99f6131 100644 (file)
--- a/kexpr.c
+++ b/kexpr.c
@@ -115,9 +115,11 @@ static ke1_t ke_read_token(char *p, char **r, int *err, int last_is_val) // it d
                        e.i = x, e.r = x;
                        *r = pp;
                }
-       } else if (*p == '"') { // a string value
-               for (++p; *p && *p != '"'; ++p); // TODO: support escaping
-               if (*p == '"') {
+       } else if (*p == '"' || *p == '\'') { // a string value
+               int c = *p;
+               for (++p; *p && *p != c; ++p)
+                       if (*p == '\\') ++p; // escaping
+               if (*p == c) {
                        e.ttype = KET_VAL;
                        e.vtype = KEV_STR;
                        e.s = strndup(q + 1, p - q - 1);