MCPcopy Create free account
hub / github.com/antirez/ds4 / dist_json_write_string

Function dist_json_write_string

ds4_distributed.c:2823–2846  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2821}
2822
2823static void dist_json_write_string(FILE *fp, const char *s, size_t n) {
2824 const bool valid_utf8 = dist_json_utf8_valid(s, n);
2825 fputc('"', fp);
2826 for (size_t i = 0; i < n; i++) {
2827 unsigned char c = (unsigned char)s[i];
2828 if (c == '"' || c == '\\') {
2829 fputc('\\', fp);
2830 fputc((char)c, fp);
2831 } else if (c == '\n') {
2832 fputs("\\n", fp);
2833 } else if (c == '\r') {
2834 fputs("\\r", fp);
2835 } else if (c == '\t') {
2836 fputs("\\t", fp);
2837 } else if (c < 0x20) {
2838 fprintf(fp, "\\u%04x", (unsigned)c);
2839 } else if (!valid_utf8 && c >= 0x80) {
2840 fprintf(fp, "\\u%04x", (unsigned)c);
2841 } else {
2842 fputc((char)c, fp);
2843 }
2844 }
2845 fputc('"', fp);
2846}
2847
2848static void dist_json_write_token(FILE *fp, ds4_engine *engine, int token) {
2849 size_t n = 0;

Callers 1

dist_json_write_tokenFunction · 0.85

Calls 1

dist_json_utf8_validFunction · 0.85

Tested by

no test coverage detected