static int json_print_string(struct lyout *out, const char *text) { unsigned int i, n; if (!text) { return 0; } ly_write(out, "\"", 1); for (i = n = 0; text[i]; i++) { if (text[i] < 0x20) { /* control character */ n += ly_print(out, "\\u%.4X"); } else { switch (text[i]) { case '"': n += ly_print(out, "\\\""); break; case '\\': n += ly_print(out, "\\\\"); break; default: ly_write(out, &text[i], 1); n++; } } } ly_write(out, "\"", 1); return n + 2; }
int ly_write_skipped(struct lyout *out, size_t position, const char *buf, size_t count) { switch (out->type) { case LYOUT_MEMORY: /* write */ memcpy(&out->method.mem.buf[position], buf, count); break; case LYOUT_FD: case LYOUT_STREAM: case LYOUT_CALLBACK: if (out->buf_len < position + count) { LOGINT(NULL); return -1; } /* write into the hole */ memcpy(&out->buffered[position], buf, count); /* decrease hole counter */ --out->hole_count; if (!out->hole_count) { /* all holes filled, we can write the buffer */ count = ly_write(out, out->buffered, out->buf_len); out->buf_len = 0; } break; } return count; }