From 8fc8c880074d01af5a2d92fbd9b2fb042bdd59f3 Mon Sep 17 00:00:00 2001 From: Gregor Beck Date: Thu, 17 Mar 2011 10:22:25 +0100 Subject: s3: add function srprs_quoted to parse strings written with cbuf_print_quoted --- source3/lib/srprs.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'source3/lib/srprs.c') diff --git a/source3/lib/srprs.c b/source3/lib/srprs.c index 77464f5f3a..5a032d27b6 100644 --- a/source3/lib/srprs.c +++ b/source3/lib/srprs.c @@ -183,3 +183,43 @@ bool srprs_line(const char** ptr, cbuf* str) ; return true; } + +bool srprs_quoted(const char** ptr, cbuf* str) +{ + const char* pos = *ptr; + const size_t spos = cbuf_getpos(str); + + if (!srprs_char(&pos, '"')) { + goto fail; + } + + while (true) { + while (srprs_charsetinv(&pos, "\\\"", str)) + ; + + switch (*pos) { + case '\0': + goto fail; + case '"': + *ptr = pos+1; + return true; + + case '\\': + pos++; + if (!srprs_charset(&pos, "\\\"", str)) { + unsigned u; + if (!srprs_hex(&pos, 2, &u)) { + goto fail; + } + cbuf_putc(str, u); + } + break; + default: + assert(false); + } + } + +fail: + cbuf_setpos(str, spos); + return false; +} -- cgit