MCPcopy Create free account
hub / github.com/Snapchat/Valdi / writeASCIIString

Method writeASCIIString

valdi_core/src/valdi_core/cpp/Utils/JSONWriter.cpp:110–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108}
109
110void JSONWriter::writeASCIIString(std::string_view str) {
111 _output.append('"');
112 const auto* it = reinterpret_cast<const Byte*>(str.data());
113 const auto* end = it + str.size();
114
115 while (it != end) {
116 auto c = *it;
117 switch (c) {
118 case '\t':
119 write("\\t");
120 break;
121 case '\n':
122 write("\\n");
123 break;
124 case '\v':
125 write("\\v");
126 break;
127 case '\f':
128 write("\\f");
129 break;
130 case '\r':
131 write("\\r");
132 break;
133 case '\x1b':
134 // Hex isn't valid JSON even when escaped
135 // so we must unicde instead.
136 writeSmallHex(c);
137 break;
138 case '"':
139 case '\\':
140 _output.append(static_cast<Byte>('\\'));
141 _output.append(c);
142 break;
143 default:
144 if (c < 0x20) {
145 writeSmallHex(c);
146 } else {
147 _output.append(c);
148 }
149 }
150 it++;
151 }
152 _output.append('"');
153}
154
155void JSONWriter::writeUnicodeString(std::string_view str) {
156 Json::FastWriter writer;

Callers

nothing calls this directly

Calls 3

appendMethod · 0.65
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected