From fbaac08df997df37f4ef4e13240ba5e9eabe74af Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Mon, 26 Oct 2015 15:57:59 +0100 Subject: parse "" as " inside strings --- lr.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'lr.c') diff --git a/lr.c b/lr.c index 82832de..16d7661 100644 --- a/lr.c +++ b/lr.c @@ -322,12 +322,28 @@ parse_type() static int parse_string(char **s) { + char *buf = 0; + size_t bufsiz = 0; + size_t len = 0; + if (*pos == '"') { pos++; - char *e = strchr(pos, '"'); - *s = strndup(pos, e - pos); - pos += e - pos + 1; + while (*pos != '"' || (*pos == '"' && *(pos+1) == '"')) { + if (len >= bufsiz) { + bufsiz = 2*bufsiz + 16; + buf = realloc(buf, bufsiz); + if (!buf) + parse_error("string too long"); + } + if (*pos == '"') + pos++; + buf[len++] = *pos++; + } + if (buf) + buf[len] = 0; + pos++; ws(); + *s = buf ? buf : (char *) ""; return 1; } -- cgit 1.4.1