X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fdump.c;h=30d54337066f2c3ce540ee89a5d45130f6a5f658;hb=2d46ea069b899404a555c5136adbf79317271b0c;hp=42511045dbca66758b5ef43e88c68c47f7c5917c;hpb=6ce273e2e65d1ea9e09e0dad3265dc5f3a2b746a;p=profile%2Fivi%2Fjansson.git diff --git a/src/dump.c b/src/dump.c index 4251104..30d5433 100644 --- a/src/dump.c +++ b/src/dump.c @@ -62,7 +62,7 @@ static int dump_indent(size_t flags, int depth, int space, json_dump_callback_t return 0; } -static int dump_string(const char *str, int ascii, json_dump_callback_t dump, void *data) +static int dump_string(const char *str, int ascii, json_dump_callback_t dump, void *data, size_t flags) { const char *pos, *end; int32_t codepoint; @@ -84,7 +84,7 @@ static int dump_string(const char *str, int ascii, json_dump_callback_t dump, vo return -1; /* mandatory escape or control char */ - if(codepoint == '\\' || codepoint == '"' || codepoint < 0x20) + if(codepoint == '\\' || codepoint == '/' || codepoint == '"' || codepoint < 0x20) break; /* non-ASCII */ @@ -102,7 +102,7 @@ static int dump_string(const char *str, int ascii, json_dump_callback_t dump, vo if(end == pos) break; - /* handle \, ", and control codes */ + /* handle \, /, ", and control codes */ length = 2; switch(codepoint) { @@ -113,6 +113,14 @@ static int dump_string(const char *str, int ascii, json_dump_callback_t dump, vo case '\n': text = "\\n"; break; case '\r': text = "\\r"; break; case '\t': text = "\\t"; break; + case '/': + if (flags & JSON_ESCAPE_SLASH) + text = "\\/"; + else { + text = "/"; + length = 1; + } + break; default: { /* codepoint is in BMP */ @@ -206,7 +214,7 @@ static int do_dump(const json_t *json, size_t flags, int depth, } case JSON_STRING: - return dump_string(json_string_value(json), ascii, dump, data); + return dump_string(json_string_value(json), ascii, dump, data, flags); case JSON_ARRAY: { @@ -327,7 +335,7 @@ static int do_dump(const json_t *json, size_t flags, int depth, value = json_object_get(json, key); assert(value); - dump_string(key, ascii, dump, data); + dump_string(key, ascii, dump, data, flags); if(dump(separator, separator_length, data) || do_dump(value, flags, depth + 1, dump, data)) { @@ -364,7 +372,7 @@ static int do_dump(const json_t *json, size_t flags, int depth, { void *next = json_object_iter_next((json_t *)json, iter); - dump_string(json_object_iter_key(iter), ascii, dump, data); + dump_string(json_object_iter_key(iter), ascii, dump, data, flags); if(dump(separator, separator_length, data) || do_dump(json_object_iter_value(iter), flags, depth + 1, dump, data))