[LTP] [PATCH 1/1] docparse: Escape backslash, tab and double quote in JSON
Petr Vorel
pvorel@suse.cz
Mon May 3 14:38:14 CEST 2021
Hi Cyril,
> I guess that it would be easier to write a function to print json
> string, e.g.
> static inline void data_fprintf_esc_(FILE *f, unsigned int padd, const char *str)
> {
> while (padd-- > 0)
> fputc(' ', f);
> fputc('"', f);
> while (*str) {
> switch (*str) {
> case '\\':
> fputs("\\\\", f);
> break;
> case '"':
> fputs("\\\"", f);
> break;
> case '\t':
> fputs("\\t", f);
> break;
> default:
> putc(*str, f);
> break;
> }
> str++;
> }
> fputc('"', f);
> }
That's indeed much better, thanks! I'll send v2 with you as author.
Kind regards,
Petr
More information about the ltp
mailing list