MCPcopy Create free account
hub / github.com/IBM/Project_CodeNet / JSON_escape

Function JSON_escape

tools/tokenizer/libtoken.c:1225–1244  ·  view source on GitHub ↗

Escape token for output as JSON string.

Source from the content-addressed store, hash-verified

1223
1224// Escape token for output as JSON string.
1225void JSON_escape(FILE *out, const char *token)
1226{
1227 // C/C++ has escapes: \' \" \? \a \b \f \n \r \t \v \x \0.
1228 // To preserve, simply escape the backslash and all ":
1229 const char *p;
1230 for (p = token; *p; p++) {
1231 if (*p == '\n') { // escape embedded real new lines
1232 fputs("\\n", out);
1233 continue;
1234 }
1235 if (*p == '\t') { // escape embedded real TABs
1236 fputs("\\t", out);
1237 continue;
1238 }
1239 // FIXME: control characters from U+0000 through U+001F must be escaped
1240 if (*p == '\\' || *p == '"')
1241 fputc('\\', out);
1242 fputc(*p, out);
1243 }
1244}
1245
1246// Escape token for output as XML text.
1247void XML_escape(FILE *out, const char *token)

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected