MCPcopy Create free account
hub / github.com/couchbase/fleece / writeString

Method writeString

Fleece/Support/JSONEncoder.cc:22–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20namespace fleece { namespace impl {
21
22 void JSONEncoder::writeString(slice str) {
23 comma();
24 _out << '"';
25 auto start = (const uint8_t*)str.buf;
26 auto end = (const uint8_t*)str.end();
27 for (auto p = start; p < end; p++) {
28 uint8_t ch = *p;
29 if (ch == '"' || ch == '\\' || ch < 32 || ch == 127) {
30 // Write characters from start up to p-1:
31 _out.write({start, p});
32 start = p + 1;
33 switch (ch) {
34 case '"':
35 case '\\':
36 _out << '\\';
37 --start; // ch will be written in next pass
38 break;
39 case '\r':
40 _out.write("\\r"_sl);
41 break;
42 case '\n':
43 _out.write("\\n"_sl);
44 break;
45 case '\t':
46 _out.write("\\t"_sl);
47 break;
48 default: {
49 char buf[7];
50 _out.write(buf, sprintf(buf, "\\u%04x", (unsigned)ch));
51 break;
52 }
53 }
54 }
55 }
56 if (end > start)
57 _out.write({start, end});
58 _out << '"';
59 }
60
61
62 void JSONEncoder::writeDateString(int64_t timestamp, bool asUTC) {

Callers 1

writeToMethod · 0.45

Calls 2

endMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected