All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/1] docparse: Escape backslash, tab and double quote in JSON
Date: Mon, 3 May 2021 14:38:14 +0200	[thread overview]
Message-ID: <YI/utqVeWrPjwqYQ@pevik> (raw)
In-Reply-To: <YI/jqKdP7kRYK1qD@yuki>

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

      reply	other threads:[~2021-05-03 12:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-03  8:57 [LTP] [PATCH 1/1] docparse: Escape backslash, tab and double quote in JSON Petr Vorel
2021-05-03 11:51 ` Cyril Hrubis
2021-05-03 12:38   ` Petr Vorel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YI/utqVeWrPjwqYQ@pevik \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.