From mboxrd@z Thu Jan 1 00:00:00 1970 From: Petr Vorel Date: Mon, 3 May 2021 14:38:14 +0200 Subject: [LTP] [PATCH 1/1] docparse: Escape backslash, tab and double quote in JSON In-Reply-To: References: <20210503085732.9637-1-pvorel@suse.cz> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: ltp@lists.linux.it 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