MCPcopy Create free account
hub / github.com/crawl/crawl / emit_string

Function emit_string

crawl-ref/source/json.cc:1179–1309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1177}
1178
1179void emit_string(SB *out, const char *str)
1180{
1181 bool escape_unicode = false;
1182 const char *s = str;
1183 char *b;
1184
1185 ASSERT(utf8_validate(str));
1186
1187 /*
1188 * 14 bytes is enough space to write up to two
1189 * \uXXXX escapes and two quotation marks.
1190 */
1191 sb_need(out, 14);
1192 b = out->cur;
1193
1194 *b++ = '"';
1195 while (*s != 0)
1196 {
1197 unsigned char c = *s++;
1198
1199 /* Encode the next character, and write it to b. */
1200 switch (c)
1201 {
1202 case '"':
1203 *b++ = '\\';
1204 *b++ = '"';
1205 break;
1206 case '\\':
1207 *b++ = '\\';
1208 *b++ = '\\';
1209 break;
1210 case '\b':
1211 *b++ = '\\';
1212 *b++ = 'b';
1213 break;
1214 case '\f':
1215 *b++ = '\\';
1216 *b++ = 'f';
1217 break;
1218 case '\n':
1219 *b++ = '\\';
1220 *b++ = 'n';
1221 break;
1222 case '\r':
1223 *b++ = '\\';
1224 *b++ = 'r';
1225 break;
1226 case '\t':
1227 *b++ = '\\';
1228 *b++ = 't';
1229 break;
1230 default:
1231 {
1232 int len;
1233
1234 s--;
1235 len = utf8_validate_cz(s);
1236

Callers 5

json_encode_stringFunction · 0.85
emit_valueFunction · 0.85
emit_value_indentedFunction · 0.85
json_foreachFunction · 0.85
emit_object_indentedFunction · 0.85

Calls 7

utf8_validate_czFunction · 0.85
wctoutf8Function · 0.85
utf8_read_charFunction · 0.85
write_hex16Function · 0.85
to_surrogate_pairFunction · 0.85
utf8_validateFunction · 0.70
dieFunction · 0.70

Tested by

no test coverage detected