mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 08:32:11 +01:00
Have std/cbor parse text strings
This commit is contained in:
1 parent
3c8589b6e9
commit
d191a3fc5f
3 files changed
+198
-5
No files matched your search
@@ -1192,6 +1192,30 @@ write_cbor_output_string(uint8_t* ptr, size_t len, bool finish) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char* //
|
||||
handle_unicode_code_point(uint32_t ucp);
|
||||
|
||||
const char* //
|
||||
write_json_escaped_string(uint8_t* ptr, size_t len) {
|
||||
restart:
|
||||
while (true) {
|
||||
size_t i;
|
||||
for (i = 0; i < len; i++) {
|
||||
uint8_t c = ptr[i];
|
||||
if ((c == '"') || (c == '\\') || (c < 0x20)) {
|
||||
TRY(write_dst(ptr, i));
|
||||
TRY(handle_unicode_code_point(c));
|
||||
ptr += i + 1;
|
||||
len -= i + 1;
|
||||
goto restart;
|
||||
}
|
||||
}
|
||||
TRY(write_dst(ptr, len));
|
||||
break;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char* //
|
||||
handle_string(uint64_t vbd,
|
||||
uint64_t len,
|
||||
@@ -1222,8 +1246,7 @@ handle_string(uint64_t vbd,
|
||||
if (g_flags.input_format == file_format::json) {
|
||||
TRY(write_dst(ptr, len));
|
||||
} else if (vbd & WUFFS_BASE__TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8) {
|
||||
// TODO: escape '\n', '\"', etc.
|
||||
TRY(write_dst(ptr, len));
|
||||
TRY(write_json_escaped_string(ptr, len));
|
||||
} else {
|
||||
uint8_t as_hex[512];
|
||||
uint8_t* p = ptr;
|
||||
@@ -1312,6 +1335,8 @@ handle_unicode_code_point(uint32_t ucp) {
|
||||
return write_cbor_output_string(&u[0], n, false);
|
||||
}
|
||||
|
||||
// ----
|
||||
|
||||
const char* //
|
||||
handle_token(wuffs_base__token t, bool start_of_token_chain) {
|
||||
do {
|
||||
|
||||
Reference in new issue
Block a user