* Append JSON-quoted version of the given string to 'out'. */
| 19 | * Append JSON-quoted version of the given string to 'out'. |
| 20 | */ |
| 21 | static void append_quoted_string(struct strbuf *out, const char *in) |
| 22 | { |
| 23 | unsigned char c; |
| 24 | |
| 25 | strbuf_addch(out, '"'); |
| 26 | while ((c = *in++) != '\0') { |
| 27 | if (c == '"') |
| 28 | strbuf_addstr(out, "\\\""); |
| 29 | else if (c == '\\') |
| 30 | strbuf_addstr(out, "\\\\"); |
| 31 | else if (c == '\n') |
| 32 | strbuf_addstr(out, "\\n"); |
| 33 | else if (c == '\r') |
| 34 | strbuf_addstr(out, "\\r"); |
| 35 | else if (c == '\t') |
| 36 | strbuf_addstr(out, "\\t"); |
| 37 | else if (c == '\f') |
| 38 | strbuf_addstr(out, "\\f"); |
| 39 | else if (c == '\b') |
| 40 | strbuf_addstr(out, "\\b"); |
| 41 | else if (c < 0x20) |
| 42 | strbuf_addf(out, "\\u%04x", c); |
| 43 | else |
| 44 | strbuf_addch(out, c); |
| 45 | } |
| 46 | strbuf_addch(out, '"'); |
| 47 | } |
| 48 | |
| 49 | static void indent_pretty(struct json_writer *jw) |
| 50 | { |
no test coverage detected