Rename std/json quirk_replace_invalid_utf_8

This commit is contained in:
Nigel Tao committed 2020-03-24 17:44:47 +11:00
1 parent 59eab68360
commit 3bfed6d812
6 files changed
+28 -28

No files matched your search

+1 -1
View File
@@ -234,7 +234,7 @@ void set_quirks(wuffs_json__decoder* dec, uint32_t hash_12_bits) {
WUFFS_JSON__QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR,
WUFFS_JSON__QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK,
WUFFS_JSON__QUIRK_ALLOW_TRAILING_NEW_LINE,
WUFFS_JSON__QUIRK_REPLACE_INVALID_UTF_8,
WUFFS_JSON__QUIRK_REPLACE_INVALID_UNICODE,
0,
};
+10 -10
View File
@@ -5944,7 +5944,7 @@ extern const char* wuffs_json__error__unsupported_recursion_depth;
#define WUFFS_JSON__QUIRK_ALLOW_TRAILING_NEW_LINE 1225364494
#define WUFFS_JSON__QUIRK_REPLACE_INVALID_UTF_8 1225364495
#define WUFFS_JSON__QUIRK_REPLACE_INVALID_UNICODE 1225364495
// ---------------- Struct Declarations
@@ -6020,7 +6020,7 @@ struct wuffs_json__decoder__struct {
bool f_quirk_enabled_allow_leading_ascii_record_separator;
bool f_quirk_enabled_allow_leading_unicode_byte_order_mark;
bool f_quirk_enabled_allow_trailing_new_line;
bool f_quirk_enabled_replace_invalid_utf_8;
bool f_quirk_enabled_replace_invalid_unicode;
bool f_allow_leading_ars;
bool f_allow_leading_ubom;
bool f_end_of_data;
@@ -20507,7 +20507,7 @@ wuffs_json__decoder__set_quirk_enabled(wuffs_json__decoder* self,
} else if (a_quirk == 1225364494) {
self->private_impl.f_quirk_enabled_allow_trailing_new_line = a_enabled;
} else if (a_quirk == 1225364495) {
self->private_impl.f_quirk_enabled_replace_invalid_utf_8 = a_enabled;
self->private_impl.f_quirk_enabled_replace_invalid_unicode = a_enabled;
}
return wuffs_base__make_empty_struct();
}
@@ -20878,7 +20878,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
if (((uint64_t)(io2_a_src - iop_a_src)) < 12) {
if (a_src && a_src->meta.closed) {
if (self->private_impl
.f_quirk_enabled_replace_invalid_utf_8) {
.f_quirk_enabled_replace_invalid_unicode) {
(iop_a_src += 6, wuffs_base__make_empty_struct());
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(6356989))
@@ -20947,7 +20947,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
}
}
if (self->private_impl
.f_quirk_enabled_replace_invalid_utf_8) {
.f_quirk_enabled_replace_invalid_unicode) {
if (((uint64_t)(io2_a_src - iop_a_src)) < 6) {
status = wuffs_base__make_status(
wuffs_json__error__internal_error_inconsistent_i_o);
@@ -21025,7 +21025,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
(((uint64_t)(10)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
goto label__string_loop_outer__continue;
} else if (self->private_impl
.f_quirk_enabled_replace_invalid_utf_8) {
.f_quirk_enabled_replace_invalid_unicode) {
(iop_a_src += 10, wuffs_base__make_empty_struct());
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(6356989))
@@ -21102,7 +21102,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
}
if (a_src && a_src->meta.closed) {
if (self->private_impl
.f_quirk_enabled_replace_invalid_utf_8) {
.f_quirk_enabled_replace_invalid_unicode) {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(6356989))
<< WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
@@ -21158,7 +21158,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
}
if (a_src && a_src->meta.closed) {
if (self->private_impl
.f_quirk_enabled_replace_invalid_utf_8) {
.f_quirk_enabled_replace_invalid_unicode) {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(6356989))
<< WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
@@ -21219,7 +21219,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
}
if (a_src && a_src->meta.closed) {
if (self->private_impl
.f_quirk_enabled_replace_invalid_utf_8) {
.f_quirk_enabled_replace_invalid_unicode) {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(6356989))
<< WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
@@ -21282,7 +21282,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
wuffs_json__error__bad_c0_control_code);
goto exit;
}
if (self->private_impl.f_quirk_enabled_replace_invalid_utf_8) {
if (self->private_impl.f_quirk_enabled_replace_invalid_unicode) {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(6356989))
<< WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
+1 -1
View File
@@ -240,7 +240,7 @@ main1(int argc, char** argv) {
WUFFS_JSON__QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR,
WUFFS_JSON__QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK,
WUFFS_JSON__QUIRK_ALLOW_TRAILING_NEW_LINE,
WUFFS_JSON__QUIRK_REPLACE_INVALID_UTF_8,
WUFFS_JSON__QUIRK_REPLACE_INVALID_UNICODE,
0,
};
uint32_t i;
+10 -10
View File
@@ -26,7 +26,7 @@ pub struct decoder? implements base.token_decoder(
quirk_enabled_allow_leading_ascii_record_separator : base.bool,
quirk_enabled_allow_leading_unicode_byte_order_mark : base.bool,
quirk_enabled_allow_trailing_new_line : base.bool,
quirk_enabled_replace_invalid_utf_8 : base.bool,
quirk_enabled_replace_invalid_unicode : base.bool,
allow_leading_ars : base.bool,
allow_leading_ubom : base.bool,
@@ -95,8 +95,8 @@ pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
this.quirk_enabled_allow_leading_unicode_byte_order_mark = args.enabled
} else if args.quirk == quirk_allow_trailing_new_line {
this.quirk_enabled_allow_trailing_new_line = args.enabled
} else if args.quirk == quirk_replace_invalid_utf_8 {
this.quirk_enabled_replace_invalid_utf_8 = args.enabled
} else if args.quirk == quirk_replace_invalid_unicode {
this.quirk_enabled_replace_invalid_unicode = args.enabled
}
}
@@ -417,7 +417,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
// another 8 bytes at an offset of 4.
if args.src.available() < 12 {
if args.src.is_closed() {
if this.quirk_enabled_replace_invalid_utf_8 {
if this.quirk_enabled_replace_invalid_unicode {
args.src.skip32_fast!(actual: 6, worst_case: 6)
args.dst.write_fast_token!(
value_major: 0,
@@ -478,7 +478,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
}
}
if this.quirk_enabled_replace_invalid_utf_8 {
if this.quirk_enabled_replace_invalid_unicode {
if args.src.available() < 6 {
return "#internal error: inconsistent I/O"
}
@@ -548,7 +548,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
link: 0x3,
length: 10)
continue.string_loop_outer
} else if this.quirk_enabled_replace_invalid_utf_8 {
} else if this.quirk_enabled_replace_invalid_unicode {
args.src.skip32_fast!(actual: 10, worst_case: 10)
args.dst.write_fast_token!(
value_major: 0,
@@ -622,7 +622,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
}
}
if args.src.is_closed() {
if this.quirk_enabled_replace_invalid_utf_8 {
if this.quirk_enabled_replace_invalid_unicode {
args.dst.write_fast_token!(
value_major: 0,
value_minor: 0x60_FFFD,
@@ -670,7 +670,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
}
}
if args.src.is_closed() {
if this.quirk_enabled_replace_invalid_utf_8 {
if this.quirk_enabled_replace_invalid_unicode {
args.dst.write_fast_token!(
value_major: 0,
value_minor: 0x60_FFFD,
@@ -723,7 +723,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
}
}
if args.src.is_closed() {
if this.quirk_enabled_replace_invalid_utf_8 {
if this.quirk_enabled_replace_invalid_unicode {
args.dst.write_fast_token!(
value_major: 0,
value_minor: 0x60_FFFD,
@@ -776,7 +776,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
if char == 0x80 {
return "#bad C0 control code"
}
if this.quirk_enabled_replace_invalid_utf_8 {
if this.quirk_enabled_replace_invalid_unicode {
args.dst.write_fast_token!(
value_major: 0,
value_minor: 0x60_FFFD,
+2 -2
View File
@@ -29,7 +29,7 @@ pub const quirk_allow_backslash_a base.u32 = 0x4909_9400 | 0x00
// string, equivalent to "abc\uD83D\uDCA9z", containing the U+0001F4A9 PILE OF
// POO Unicode code point. There are exactly 8 encoded bytes after each "\U".
//
// This quirk can combine with quirk_replace_invalid_utf_8.
// This quirk can combine with quirk_replace_invalid_unicode.
pub const quirk_allow_backslash_capital_u base.u32 = 0x4909_9400 | 0x01
// When this quirk is enabled, e.g. "abc\ez" is accepted as a JSON string,
@@ -170,4 +170,4 @@ pub const quirk_allow_trailing_new_line base.u32 = 0x4909_9400 | 0x0E
// When combined with quirk_allow_backslash_capital_u, a "\U12345678" 10-byte
// unit that is an invalid Unicode code point (i.e. in the range U+D800 ..=
// U+DFFF or above U+10FFFF) is similarly replaced with U+FFFD.
pub const quirk_replace_invalid_utf_8 base.u32 = 0x4909_9400 | 0x0F
pub const quirk_replace_invalid_unicode base.u32 = 0x4909_9400 | 0x0F
+4 -4
View File
@@ -833,7 +833,7 @@ test_wuffs_json_decode_interface() {
WUFFS_JSON__QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR,
WUFFS_JSON__QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK,
WUFFS_JSON__QUIRK_ALLOW_TRAILING_NEW_LINE,
WUFFS_JSON__QUIRK_REPLACE_INVALID_UTF_8,
WUFFS_JSON__QUIRK_REPLACE_INVALID_UNICODE,
0,
};
@@ -1742,7 +1742,7 @@ test_wuffs_json_decode_quirk_allow_trailing_etc() {
}
const char* //
test_wuffs_json_decode_quirk_replace_invalid_utf_8() {
test_wuffs_json_decode_quirk_replace_invalid_unicode() {
CHECK_FOCUS(__func__);
// Decoding str should produce want, with invalid UTF-8 replaced by "?". A
@@ -1797,7 +1797,7 @@ test_wuffs_json_decode_quirk_replace_invalid_utf_8() {
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
wuffs_json__decoder__set_quirk_enabled(
&dec, WUFFS_JSON__QUIRK_REPLACE_INVALID_UTF_8, true);
&dec, WUFFS_JSON__QUIRK_REPLACE_INVALID_UNICODE, true);
wuffs_base__io_buffer have =
wuffs_base__make_io_buffer_writer(global_have_slice);
@@ -2234,7 +2234,7 @@ proc tests[] = {
test_wuffs_json_decode_quirk_allow_inf_nan_numbers,
test_wuffs_json_decode_quirk_allow_leading_etc,
test_wuffs_json_decode_quirk_allow_trailing_etc,
test_wuffs_json_decode_quirk_replace_invalid_utf_8,
test_wuffs_json_decode_quirk_replace_invalid_unicode,
test_wuffs_json_decode_src_io_buffer_length,
test_wuffs_json_decode_string,
test_wuffs_json_decode_unicode4_escapes,