From 0c9f5eb2eeb4927e51f43ac2cba85cebca873234 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 24 Mar 2013 05:53:56 +0000 Subject: Set SERD_HAS_NEWLINE and SERD_HAS_QUOTE flags when unescaped newlines or quotes are read. Don't escape legal ASCII characters when writing long literals. git-svn-id: http://svn.drobilla.net/serd/trunk@439 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- src/writer.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/writer.c') diff --git a/src/writer.c b/src/writer.c index 78a8347f..83ad6e20 100644 --- a/src/writer.c +++ b/src/writer.c @@ -284,10 +284,20 @@ write_text(SerdWriter* writer, TextContext ctx, uint8_t in = utf8[i++]; if (ctx == WRITE_LONG_STRING) { - if (in == '\\') { - len += sink("\\\\", 2, writer); continue; - } else if (in == '\"' && i == n_bytes) { - len += sink("\\\"", 2, writer); continue; // '"' at string end + switch (in) { + case '\\': len += sink("\\\\", 2, writer); continue; + case '\b': len += sink("\\b", 2, writer); continue; + case '\n': case '\r': case '\t': case '\f': + len += sink(&in, 1, writer); // Write character as-is + continue; + case '\"': + if (i == n_bytes) { // '"' at string end + len += sink("\\\"", 2, writer); + } else { + len += sink(&in, 1, writer); + } + continue; + default: break; } } else if (ctx == WRITE_STRING) { switch (in) { -- cgit v1.2.1