mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-04-07 11:07:00 +00:00
Do escaping in output strings
This commit is contained in:
parent
9299ef2ecb
commit
c69e595e4e
15
jsoncat.c
15
jsoncat.c
@ -16,7 +16,20 @@ void json_print(json_object *j, int depth) {
|
||||
if (j == NULL) {
|
||||
printf("NULL");
|
||||
} else if (j->type == JSON_STRING) {
|
||||
printf("\"%s\"", j->string);
|
||||
printf("\"");
|
||||
|
||||
char *cp;
|
||||
for (cp = j->string; *cp != '\0'; cp++) {
|
||||
if (*cp == '\\' || *cp == '"') {
|
||||
printf("\\%c", *cp);
|
||||
} else if (*cp >= 0 && *cp < ' ') {
|
||||
printf("\\u%04x", *cp);
|
||||
} else {
|
||||
putchar(*cp);
|
||||
}
|
||||
}
|
||||
|
||||
printf("\"");
|
||||
} else if (j->type == JSON_NUMBER) {
|
||||
printf("%f", j->number);
|
||||
} else if (j->type == JSON_NULL) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user