mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 08:38:14 +01:00
Capitalize Wuffs const names
This commit is contained in:
1 parent
623811086f
commit
74871344f0
20 files changed
+338
-335
No files matched your search
@@ -21,20 +21,20 @@ pub status "#unsupported recursion depth"
|
||||
|
||||
pri status "#internal error: inconsistent I/O"
|
||||
|
||||
pub const decoder_workbuf_len_max_incl_worst_case base.u64 = 0
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE base.u64 = 0
|
||||
|
||||
// decoder_depth_max_incl is the maximum supported recursion depth: how deeply
|
||||
// DECODER_DEPTH_MAX_INCL is the maximum supported recursion depth: how deeply
|
||||
// nested [] arrays and {} objects can be.
|
||||
//
|
||||
// The JSON spec itself does not define a limit, but allows implementations to
|
||||
// set their own limits.
|
||||
pub const decoder_depth_max_incl base.u64 = 1024
|
||||
pub const DECODER_DEPTH_MAX_INCL base.u64 = 1024
|
||||
|
||||
// decoder_dst_token_buffer_length_min_incl is the minimum length of the dst
|
||||
// DECODER_DST_TOKEN_BUFFER_LENGTH_MIN_INCL is the minimum length of the dst
|
||||
// wuffs_base__token_buffer passed to the decoder.
|
||||
pub const decoder_dst_token_buffer_length_min_incl base.u64 = 1
|
||||
pub const DECODER_DST_TOKEN_BUFFER_LENGTH_MIN_INCL base.u64 = 1
|
||||
|
||||
// decoder_src_io_buffer_length_min_incl is the minimum length of the src
|
||||
// DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL is the minimum length of the src
|
||||
// wuffs_base__io_buffer passed to the decoder.
|
||||
//
|
||||
// This constrains the src.data.len field and it is the io_buffer capacity (the
|
||||
@@ -42,9 +42,9 @@ pub const decoder_dst_token_buffer_length_min_incl base.u64 = 1
|
||||
// the backing array's length, not the length of the JSON-formatted input per
|
||||
// se. It is perfectly valid to decode "[1,2]" (of length 5) as JSON, as long
|
||||
// as that content is placed in an io_buffer whose data.len is at least 100.
|
||||
pub const decoder_src_io_buffer_length_min_incl base.u64 = 100
|
||||
pub const DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL base.u64 = 100
|
||||
|
||||
// decoder_number_length_max_incl is the longest supported byte length for a
|
||||
// DECODER_NUMBER_LENGTH_MAX_INCL is the longest supported byte length for a
|
||||
// JSON number. Unlike JSON strings, this package's tokenizer never splits a
|
||||
// single JSON number into multiple tokens, as this simplifies the callers.
|
||||
// They can then call e.g. wuffs_base__parse_number_i64 without having to
|
||||
@@ -52,17 +52,17 @@ pub const decoder_src_io_buffer_length_min_incl base.u64 = 100
|
||||
//
|
||||
// The JSON spec itself does not define a limit, but allows implementations to
|
||||
// set their own limits.
|
||||
pri const decoder_number_length_max_incl base.u64 = 99
|
||||
pri const DECODER_NUMBER_LENGTH_MAX_INCL base.u64 = 99
|
||||
|
||||
// --------
|
||||
|
||||
// Look-Up Tables (LUTs).
|
||||
|
||||
// lut_backslashes[i] helps decode "\i", for various 'i's.
|
||||
// LUT_BACKSLASHES[i] helps decode "\i", for various 'i's.
|
||||
//
|
||||
// If the element's 0x80 bit is set then "\i" is unconditionally a valid
|
||||
// single-output-byte backslash-escape. The low 7 bits are the unescaped value.
|
||||
// For example, lut_backslashes['n'] is (0x80 | 0x0A), because "\n" is U+000A.
|
||||
// For example, LUT_BACKSLASHES['n'] is (0x80 | 0x0A), because "\n" is U+000A.
|
||||
//
|
||||
// If the element is non-zero (but the 0x80 bit is not set) then "\i"'s
|
||||
// validity depends on the relevant quirk. The element's value is an enum:
|
||||
@@ -73,11 +73,11 @@ pri const decoder_number_length_max_incl base.u64 = 99
|
||||
// - 5: "\'", U+0027, quirk_allow_backslash_single_quote.
|
||||
// - 6: "\v", U+000B, quirk_allow_backslash_v.
|
||||
// - 7: "\0", U+0000, quirk_allow_backslash_zero.
|
||||
// The U+1234 values are held in lut_quirky_backslashes, below.
|
||||
// The U+1234 values are held in LUT_QUIRKY_BACKSLASHES, below.
|
||||
//
|
||||
// If the element is zero then "\i" is invalid, or it is a special case, the
|
||||
// start of "\x12", "\u1234" or "\U12345678".
|
||||
pri const lut_backslashes array[256] base.u8 = [
|
||||
pri const LUT_BACKSLASHES array[256] base.u8 = [
|
||||
// 0 1 2 3 4 5 6 7
|
||||
// 8 9 A B C D E F
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00 ..= 0x07.
|
||||
@@ -119,14 +119,14 @@ pri const lut_backslashes array[256] base.u8 = [
|
||||
// 8 9 A B C D E F
|
||||
]
|
||||
|
||||
// lut_quirky_backslashes is discussed in the lut_backslashes comment. The
|
||||
// LUT_QUIRKY_BACKSLASHES is discussed in the LUT_BACKSLASHES comment. The
|
||||
// first element (index 0) is not used, but 8 is a round power of 2, so
|
||||
// enforcing index-in-bounds is a simple "&7" operation.
|
||||
pri const lut_quirky_backslashes array[8] base.u8 = [
|
||||
pri const LUT_QUIRKY_BACKSLASHES array[8] base.u8 = [
|
||||
0x00, 0x07, 0x1B, 0x0A, 0x3F, 0x27, 0x0B, 0x00,
|
||||
]
|
||||
|
||||
// lut_chars helps decode bytes within a string:
|
||||
// LUT_CHARS helps decode bytes within a string:
|
||||
// - 0x00 is 1-byte UTF-8 (ASCII) but not '"', '\\' or a C0 control code.
|
||||
// - 0x01 is '"'.
|
||||
// - 0x02 is '\\'.
|
||||
@@ -145,7 +145,7 @@ pri const lut_quirky_backslashes array[8] base.u8 = [
|
||||
// UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
|
||||
// %xF4 %x80-8F 2( UTF8-tail )
|
||||
// UTF8-tail = %x80-BF
|
||||
pri const lut_chars array[256] base.u8 = [
|
||||
pri const LUT_CHARS array[256] base.u8 = [
|
||||
// 0 1 2 3 4 5 6 7
|
||||
// 8 9 A B C D E F
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, // 0x00 ..= 0x07. C0 control codes.
|
||||
@@ -187,7 +187,7 @@ pri const lut_chars array[256] base.u8 = [
|
||||
// 8 9 A B C D E F
|
||||
]
|
||||
|
||||
// lut_classes is:
|
||||
// LUT_CLASSES is:
|
||||
// - 0x00 (bitmask 0x0001) is CLASS_WHITESPACE.
|
||||
// - 0x01 (bitmask 0x0002) is CLASS_STRING.
|
||||
// - 0x02 (bitmask 0x0004) is CLASS_COMMA.
|
||||
@@ -231,7 +231,7 @@ pri const lut_chars array[256] base.u8 = [
|
||||
//
|
||||
// Comments are always expected. Whether the relevant quirks are enabled are
|
||||
// checked elsewhere.
|
||||
pri const lut_classes array[256] base.u8[..= 0x0F] = [
|
||||
pri const LUT_CLASSES array[256] base.u8[..= 0x0F] = [
|
||||
// 0 1 2 3 4 5 6 7
|
||||
// 8 9 A B C D E F
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, // 0x00 ..= 0x07.
|
||||
@@ -273,7 +273,7 @@ pri const lut_classes array[256] base.u8[..= 0x0F] = [
|
||||
// 8 9 A B C D E F
|
||||
]
|
||||
|
||||
pri const lut_decimal_digits array[256] base.u8 = [
|
||||
pri const LUT_DECIMAL_DIGITS array[256] base.u8 = [
|
||||
// 0 1 2 3 4 5 6 7
|
||||
// 8 9 A B C D E F
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00 ..= 0x07.
|
||||
@@ -315,7 +315,7 @@ pri const lut_decimal_digits array[256] base.u8 = [
|
||||
// 8 9 A B C D E F
|
||||
]
|
||||
|
||||
pri const lut_hexadecimal_digits array[256] base.u8 = [
|
||||
pri const LUT_HEXADECIMAL_DIGITS array[256] base.u8 = [
|
||||
// 0 1 2 3 4 5 6 7
|
||||
// 8 9 A B C D E F
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00 ..= 0x07.
|
||||
|
||||
+50
-50
@@ -14,7 +14,7 @@
|
||||
|
||||
pub struct decoder? implements base.token_decoder(
|
||||
// quirk_enabled_allow_backslash_etc, an 8-element array, is indexed by the
|
||||
// same enum as lut_quirky_backslashes.
|
||||
// same enum as LUT_QUIRKY_BACKSLASHES.
|
||||
quirk_enabled_allow_backslash_etc : array[8] base.bool,
|
||||
|
||||
quirk_enabled_allow_ascii_control_codes : base.bool,
|
||||
@@ -53,7 +53,7 @@ pub struct decoder? implements base.token_decoder(
|
||||
// Wuffs code does not have the capability to dynamically allocate memory,
|
||||
// so the maximum depth is hard-coded at compile time. In this case, the
|
||||
// maximum is 1024 (stack is 1024 bits or 128 bytes), also known as
|
||||
// decoder_depth_max_incl.
|
||||
// DECODER_DEPTH_MAX_INCL.
|
||||
//
|
||||
// The [JSON spec](https://www.ietf.org/rfc/rfc8259.txt) clearly states,
|
||||
// "an implementation may set limits on the maximum depth of nesting".
|
||||
@@ -68,41 +68,41 @@ pub struct decoder? implements base.token_decoder(
|
||||
)
|
||||
|
||||
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
|
||||
if args.quirk == quirk_allow_ascii_control_codes {
|
||||
if args.quirk == QUIRK_ALLOW_ASCII_CONTROL_CODES {
|
||||
this.quirk_enabled_allow_ascii_control_codes = args.enabled
|
||||
} else if args.quirk == quirk_allow_backslash_a {
|
||||
} else if args.quirk == QUIRK_ALLOW_BACKSLASH_A {
|
||||
this.quirk_enabled_allow_backslash_etc[1] = args.enabled
|
||||
} else if args.quirk == quirk_allow_backslash_capital_u {
|
||||
} else if args.quirk == QUIRK_ALLOW_BACKSLASH_CAPITAL_U {
|
||||
this.quirk_enabled_allow_backslash_capital_u = args.enabled
|
||||
} else if args.quirk == quirk_allow_backslash_e {
|
||||
} else if args.quirk == QUIRK_ALLOW_BACKSLASH_E {
|
||||
this.quirk_enabled_allow_backslash_etc[2] = args.enabled
|
||||
} else if args.quirk == quirk_allow_backslash_new_line {
|
||||
} else if args.quirk == QUIRK_ALLOW_BACKSLASH_NEW_LINE {
|
||||
this.quirk_enabled_allow_backslash_etc[3] = args.enabled
|
||||
} else if args.quirk == quirk_allow_backslash_question_mark {
|
||||
} else if args.quirk == QUIRK_ALLOW_BACKSLASH_QUESTION_MARK {
|
||||
this.quirk_enabled_allow_backslash_etc[4] = args.enabled
|
||||
} else if args.quirk == quirk_allow_backslash_single_quote {
|
||||
} else if args.quirk == QUIRK_ALLOW_BACKSLASH_SINGLE_QUOTE {
|
||||
this.quirk_enabled_allow_backslash_etc[5] = args.enabled
|
||||
} else if args.quirk == quirk_allow_backslash_v {
|
||||
} else if args.quirk == QUIRK_ALLOW_BACKSLASH_V {
|
||||
this.quirk_enabled_allow_backslash_etc[6] = args.enabled
|
||||
} else if args.quirk == quirk_allow_backslash_x {
|
||||
} else if args.quirk == QUIRK_ALLOW_BACKSLASH_X {
|
||||
this.quirk_enabled_allow_backslash_x = args.enabled
|
||||
} else if args.quirk == quirk_allow_backslash_zero {
|
||||
} else if args.quirk == QUIRK_ALLOW_BACKSLASH_ZERO {
|
||||
this.quirk_enabled_allow_backslash_etc[7] = args.enabled
|
||||
} else if args.quirk == quirk_allow_comment_block {
|
||||
} else if args.quirk == QUIRK_ALLOW_COMMENT_BLOCK {
|
||||
this.quirk_enabled_allow_comment_block = args.enabled
|
||||
} else if args.quirk == quirk_allow_comment_line {
|
||||
} else if args.quirk == QUIRK_ALLOW_COMMENT_LINE {
|
||||
this.quirk_enabled_allow_comment_line = args.enabled
|
||||
} else if args.quirk == quirk_allow_extra_comma {
|
||||
} else if args.quirk == QUIRK_ALLOW_EXTRA_COMMA {
|
||||
this.quirk_enabled_allow_extra_comma = args.enabled
|
||||
} else if args.quirk == quirk_allow_inf_nan_numbers {
|
||||
} else if args.quirk == QUIRK_ALLOW_INF_NAN_NUMBERS {
|
||||
this.quirk_enabled_allow_inf_nan_numbers = args.enabled
|
||||
} else if args.quirk == quirk_allow_leading_ascii_record_separator {
|
||||
} else if args.quirk == QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR {
|
||||
this.quirk_enabled_allow_leading_ascii_record_separator = args.enabled
|
||||
} else if args.quirk == quirk_allow_leading_unicode_byte_order_mark {
|
||||
} else if args.quirk == QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK {
|
||||
this.quirk_enabled_allow_leading_unicode_byte_order_mark = args.enabled
|
||||
} else if args.quirk == quirk_allow_trailing_new_line {
|
||||
} 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_unicode {
|
||||
} else if args.quirk == QUIRK_REPLACE_INVALID_UNICODE {
|
||||
this.quirk_enabled_replace_invalid_unicode = args.enabled
|
||||
}
|
||||
}
|
||||
@@ -201,7 +201,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
}
|
||||
|
||||
c = args.src.peek_u8()
|
||||
class = lut_classes[c]
|
||||
class = LUT_CLASSES[c]
|
||||
if class <> 0x00 { // 0x00 is CLASS_WHITESPACE.
|
||||
break.ws
|
||||
}
|
||||
@@ -288,10 +288,10 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
inv args.src.available() > 0,
|
||||
{
|
||||
c4 = args.src.peek_u32le()
|
||||
if 0x00 <> (lut_chars[0xFF & (c4 >> 0)] |
|
||||
lut_chars[0xFF & (c4 >> 8)] |
|
||||
lut_chars[0xFF & (c4 >> 16)] |
|
||||
lut_chars[0xFF & (c4 >> 24)]) {
|
||||
if 0x00 <> (LUT_CHARS[0xFF & (c4 >> 0)] |
|
||||
LUT_CHARS[0xFF & (c4 >> 8)] |
|
||||
LUT_CHARS[0xFF & (c4 >> 16)] |
|
||||
LUT_CHARS[0xFF & (c4 >> 24)]) {
|
||||
break
|
||||
}
|
||||
args.src.skip32_fast!(actual: 4, worst_case: 4)
|
||||
@@ -308,7 +308,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
} endwhile
|
||||
|
||||
c = args.src.peek_u8()
|
||||
char = lut_chars[c]
|
||||
char = LUT_CHARS[c]
|
||||
|
||||
if char == 0x00 { // Non-special ASCII.
|
||||
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||
@@ -359,7 +359,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
continue.string_loop_outer
|
||||
}
|
||||
c = (args.src.peek_u16le() >> 8) as base.u8
|
||||
backslash = lut_backslashes[c]
|
||||
backslash = LUT_BACKSLASHES[c]
|
||||
if (backslash & 0x80) <> 0 {
|
||||
args.src.skip32_fast!(actual: 2, worst_case: 2)
|
||||
args.dst.write_simple_token_fast!(
|
||||
@@ -374,7 +374,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
args.src.skip32_fast!(actual: 2, worst_case: 2)
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: 0x60_0000 | (lut_quirky_backslashes[backslash & 7] as base.u32),
|
||||
value_minor: 0x60_0000 | (LUT_QUIRKY_BACKSLASHES[backslash & 7] as base.u32),
|
||||
continued: 1,
|
||||
length: 2)
|
||||
continue.string_loop_outer
|
||||
@@ -396,16 +396,16 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
uni4_value = 0
|
||||
uni4_ok = 0x80
|
||||
|
||||
c = lut_hexadecimal_digits[0xFF & (uni4_string >> 0)]
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 0)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 12
|
||||
c = lut_hexadecimal_digits[0xFF & (uni4_string >> 8)]
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 8)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 8
|
||||
c = lut_hexadecimal_digits[0xFF & (uni4_string >> 16)]
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 16)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 4
|
||||
c = lut_hexadecimal_digits[0xFF & (uni4_string >> 24)]
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 24)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 0
|
||||
|
||||
@@ -467,16 +467,16 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
uni4_ok = 0x80
|
||||
uni4_string >>= 16
|
||||
|
||||
c = lut_hexadecimal_digits[0xFF & (uni4_string >> 0)]
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 0)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 12
|
||||
c = lut_hexadecimal_digits[0xFF & (uni4_string >> 8)]
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 8)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 8
|
||||
c = lut_hexadecimal_digits[0xFF & (uni4_string >> 16)]
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 16)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 4
|
||||
c = lut_hexadecimal_digits[0xFF & (uni4_string >> 24)]
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni4_string >> 24)]
|
||||
uni4_ok &= c
|
||||
uni4_value |= ((c & 0x0F) as base.u32) << 0
|
||||
}
|
||||
@@ -527,28 +527,28 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
uni8_value = 0
|
||||
uni8_ok = 0x80
|
||||
|
||||
c = lut_hexadecimal_digits[0xFF & (uni8_string >> 0)]
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 0)]
|
||||
uni8_ok &= c
|
||||
uni8_value |= ((c & 0x0F) as base.u32) << 28
|
||||
c = lut_hexadecimal_digits[0xFF & (uni8_string >> 8)]
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 8)]
|
||||
uni8_ok &= c
|
||||
uni8_value |= ((c & 0x0F) as base.u32) << 24
|
||||
c = lut_hexadecimal_digits[0xFF & (uni8_string >> 16)]
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 16)]
|
||||
uni8_ok &= c
|
||||
uni8_value |= ((c & 0x0F) as base.u32) << 20
|
||||
c = lut_hexadecimal_digits[0xFF & (uni8_string >> 24)]
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 24)]
|
||||
uni8_ok &= c
|
||||
uni8_value |= ((c & 0x0F) as base.u32) << 16
|
||||
c = lut_hexadecimal_digits[0xFF & (uni8_string >> 32)]
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 32)]
|
||||
uni8_ok &= c
|
||||
uni8_value |= ((c & 0x0F) as base.u32) << 12
|
||||
c = lut_hexadecimal_digits[0xFF & (uni8_string >> 40)]
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 40)]
|
||||
uni8_ok &= c
|
||||
uni8_value |= ((c & 0x0F) as base.u32) << 8
|
||||
c = lut_hexadecimal_digits[0xFF & (uni8_string >> 48)]
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 48)]
|
||||
uni8_ok &= c
|
||||
uni8_value |= ((c & 0x0F) as base.u32) << 4
|
||||
c = lut_hexadecimal_digits[0xFF & (uni8_string >> 56)]
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (uni8_string >> 56)]
|
||||
uni8_ok &= c
|
||||
uni8_value |= ((c & 0x0F) as base.u32) << 0
|
||||
|
||||
@@ -597,9 +597,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
backslash_x_string = args.src.peek_u32le()
|
||||
backslash_x_ok = 0x80
|
||||
|
||||
c = lut_hexadecimal_digits[0xFF & (backslash_x_string >> 16)]
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (backslash_x_string >> 16)]
|
||||
backslash_x_ok &= c
|
||||
c = lut_hexadecimal_digits[0xFF & (backslash_x_string >> 24)]
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (backslash_x_string >> 24)]
|
||||
backslash_x_ok &= c
|
||||
|
||||
if (backslash_x_ok == 0) or
|
||||
@@ -1290,12 +1290,12 @@ pri func decoder.decode_digits!(src: base.io_reader, n: base.u32[..= 99]) base.u
|
||||
break
|
||||
}
|
||||
c = args.src.peek_u8()
|
||||
if 0x00 == lut_decimal_digits[c] {
|
||||
if 0x00 == LUT_DECIMAL_DIGITS[c] {
|
||||
break
|
||||
}
|
||||
// Cap decoder_number_length_max_incl at an arbitrary value, 99. The
|
||||
// Cap DECODER_NUMBER_LENGTH_MAX_INCL at an arbitrary value, 99. The
|
||||
// caller's src.data.len should therefore be at least 100, also known
|
||||
// as decoder_src_io_buffer_length_min_incl.
|
||||
// as DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL.
|
||||
//
|
||||
// An example of a JSON number that is 81 bytes long is:
|
||||
// https://github.com/nst/JSONTestSuite/blob/master/test_parsing/y_number_double_close_to_zero.json
|
||||
@@ -1630,7 +1630,7 @@ pri func decoder.decode_trailing_new_line?(dst: base.token_writer, src: base.io_
|
||||
}
|
||||
|
||||
c = args.src.peek_u8()
|
||||
if lut_classes[c] <> 0x00 { // 0x00 is CLASS_WHITESPACE.
|
||||
if LUT_CLASSES[c] <> 0x00 { // 0x00 is CLASS_WHITESPACE.
|
||||
if whitespace_length > 0 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0, value_minor: 0, continued: 0, length: whitespace_length)
|
||||
|
||||
@@ -29,50 +29,50 @@
|
||||
//
|
||||
// This allows for multi-line strings, where a literal new line in the encoding
|
||||
// becomes a literal new line in the decoding. A backslash before a new line is
|
||||
// still a syntax error, unless combined with quirk_allow_backslash_new_line.
|
||||
// still a syntax error, unless combined with QUIRK_ALLOW_BACKSLASH_NEW_LINE.
|
||||
//
|
||||
// Any indentation following a new line is not stripped, but remains part of
|
||||
// the decoded string.
|
||||
pub const quirk_allow_ascii_control_codes base.u32 = 0x4909_9400 | 0x00
|
||||
pub const QUIRK_ALLOW_ASCII_CONTROL_CODES base.u32 = 0x4909_9400 | 0x00
|
||||
|
||||
// When this quirk is enabled, e.g. "abc\az" is accepted as a JSON string,
|
||||
// equivalent to "abc\u0007z", containing an ASCII Bell control character.
|
||||
pub const quirk_allow_backslash_a base.u32 = 0x4909_9400 | 0x01
|
||||
pub const QUIRK_ALLOW_BACKSLASH_A base.u32 = 0x4909_9400 | 0x01
|
||||
|
||||
// When this quirk is enabled, e.g. "abc\U0001F4A9z" is accepted as a JSON
|
||||
// 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_unicode.
|
||||
pub const quirk_allow_backslash_capital_u base.u32 = 0x4909_9400 | 0x02
|
||||
// This quirk can combine with QUIRK_REPLACE_INVALID_UNICODE.
|
||||
pub const QUIRK_ALLOW_BACKSLASH_CAPITAL_U base.u32 = 0x4909_9400 | 0x02
|
||||
|
||||
// When this quirk is enabled, e.g. "abc\ez" is accepted as a JSON string,
|
||||
// equivalent to "abc\u001Bz", containing an ASCII Escape control character.
|
||||
pub const quirk_allow_backslash_e base.u32 = 0x4909_9400 | 0x03
|
||||
pub const QUIRK_ALLOW_BACKSLASH_E base.u32 = 0x4909_9400 | 0x03
|
||||
|
||||
// When this quirk is enabled, e.g. ("abc\
|
||||
// z") is accepted as a JSON string, equivalent to "abc\nz".
|
||||
//
|
||||
// This allows for multi-line strings, if each new line is preceded by a
|
||||
// backslash. This doesn't combine per se with quirk_allow_ascii_control_codes,
|
||||
// backslash. This doesn't combine per se with QUIRK_ALLOW_ASCII_CONTROL_CODES,
|
||||
// but they have similar consequences.
|
||||
//
|
||||
// Any indentation following a new line is not stripped, but remains part of
|
||||
// the decoded string.
|
||||
pub const quirk_allow_backslash_new_line base.u32 = 0x4909_9400 | 0x04
|
||||
pub const QUIRK_ALLOW_BACKSLASH_NEW_LINE base.u32 = 0x4909_9400 | 0x04
|
||||
|
||||
// When this quirk is enabled, e.g. "abc\?z" is accepted as a JSON string,
|
||||
// equivalent to "abc?z".
|
||||
pub const quirk_allow_backslash_question_mark base.u32 = 0x4909_9400 | 0x05
|
||||
pub const QUIRK_ALLOW_BACKSLASH_QUESTION_MARK base.u32 = 0x4909_9400 | 0x05
|
||||
|
||||
// When this quirk is enabled, e.g. "abc\'z" is accepted as a JSON string,
|
||||
// equivalent to "abc'z".
|
||||
pub const quirk_allow_backslash_single_quote base.u32 = 0x4909_9400 | 0x06
|
||||
pub const QUIRK_ALLOW_BACKSLASH_SINGLE_QUOTE base.u32 = 0x4909_9400 | 0x06
|
||||
|
||||
// When this quirk is enabled, e.g. "abc\vz" is accepted as a JSON string,
|
||||
// equivalent to "abc\u000Bz", containing an ASCII Vertical Tab control
|
||||
// character.
|
||||
pub const quirk_allow_backslash_v base.u32 = 0x4909_9400 | 0x07
|
||||
pub const QUIRK_ALLOW_BACKSLASH_V base.u32 = 0x4909_9400 | 0x07
|
||||
|
||||
// When this quirk is enabled, e.g. "abc\xeFz" is accepted as a JSON string,
|
||||
// There are exactly 2 encoded bytes after each "\x".
|
||||
@@ -91,22 +91,22 @@ pub const quirk_allow_backslash_v base.u32 = 0x4909_9400 | 0x07
|
||||
// 0xAF and 0x7A. The UTF-8 encoding of U+00EF LATIN SMALL LETTER I WITH
|
||||
// DIAERESIS is the two byte sequence (0xC3, 0xAF). Decoded strings are still
|
||||
// valid UTF-8 and tokens still split on UTF-8 boundaries.
|
||||
pub const quirk_allow_backslash_x base.u32 = 0x4909_9400 | 0x08
|
||||
pub const QUIRK_ALLOW_BACKSLASH_X base.u32 = 0x4909_9400 | 0x08
|
||||
|
||||
// When this quirk is enabled, e.g. "abc\0z" is accepted as a JSON string,
|
||||
// equivalent to "abc\u0000z", containing an ASCII NUL control character.
|
||||
pub const quirk_allow_backslash_zero base.u32 = 0x4909_9400 | 0x09
|
||||
pub const QUIRK_ALLOW_BACKSLASH_ZERO base.u32 = 0x4909_9400 | 0x09
|
||||
|
||||
// When this quirk is enabled, "/* C/C++ style block comments */" are accepted
|
||||
// anywhere whitespace would be, although see the quirk_allow_trailing_new_line
|
||||
// anywhere whitespace would be, although see the QUIRK_ALLOW_TRAILING_NEW_LINE
|
||||
// comment for additional interaction when combining multiple quirks.
|
||||
//
|
||||
// They produce WUFFS_BASE__TOKEN__VBD__FILLER__COMMENT_BLOCK tokens. The token
|
||||
// chain's source bytes includes the starting "/*" and the ending "*/".
|
||||
pub const quirk_allow_comment_block base.u32 = 0x4909_9400 | 0x0A
|
||||
pub const QUIRK_ALLOW_COMMENT_BLOCK base.u32 = 0x4909_9400 | 0x0A
|
||||
|
||||
// When this quirk is enabled, "// C/C++ style line comments\n" are accepted
|
||||
// anywhere whitespace would be, although see the quirk_allow_trailing_new_line
|
||||
// anywhere whitespace would be, although see the QUIRK_ALLOW_TRAILING_NEW_LINE
|
||||
// comment for additional interaction when combining multiple quirks.
|
||||
//
|
||||
// A line comment may not omit the ending "\n", even if there is no input
|
||||
@@ -118,7 +118,7 @@ pub const quirk_allow_comment_block base.u32 = 0x4909_9400 | 0x0A
|
||||
// Even if the line comments are on consecutive lines, each line comment is a
|
||||
// separate token chain. There may be whitespace tokens between one line
|
||||
// comment's ending "\n" and the next one's starting "//".
|
||||
pub const quirk_allow_comment_line base.u32 = 0x4909_9400 | 0x0B
|
||||
pub const QUIRK_ALLOW_COMMENT_LINE base.u32 = 0x4909_9400 | 0x0B
|
||||
|
||||
// When this quirk is enabled, there may be a comma after the final array
|
||||
// element or object key-value pair and before the closing "]" or "}". A comma
|
||||
@@ -127,31 +127,31 @@ pub const quirk_allow_comment_line base.u32 = 0x4909_9400 | 0x0B
|
||||
//
|
||||
// For example, `[1,]`, `[1,2,3,]` and `{"k":"v",}` all become acceptable, but
|
||||
// `[,]`, `{,}` and `{"k",:"v"}` are still rejected.
|
||||
pub const quirk_allow_extra_comma base.u32 = 0x4909_9400 | 0x0C
|
||||
pub const QUIRK_ALLOW_EXTRA_COMMA base.u32 = 0x4909_9400 | 0x0C
|
||||
|
||||
// When this quirk is enabled, "inf", "Infinity", "NAN" and their
|
||||
// case-insensitive variants, optionally preceded immediately by "-" or "+",
|
||||
// are accepted anywhere a JSON number would be.
|
||||
pub const quirk_allow_inf_nan_numbers base.u32 = 0x4909_9400 | 0x0D
|
||||
pub const QUIRK_ALLOW_INF_NAN_NUMBERS base.u32 = 0x4909_9400 | 0x0D
|
||||
|
||||
// When this quirk is enabled, the input byte stream may optionally start with
|
||||
// "\x1E" (the ASCII Record Separator control character). That byte is skipped
|
||||
// and decoding proceeds normally.
|
||||
//
|
||||
// When combined with quirk_allow_leading_unicode_byte_order_mark, either mark
|
||||
// When combined with QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK, either mark
|
||||
// may come first in the byte stream.
|
||||
//
|
||||
// When combined with quirk_allow_trailing_new_line, this format is also known
|
||||
// When combined with QUIRK_ALLOW_TRAILING_NEW_LINE, this format is also known
|
||||
// as RFC 7464, Json Text Sequences and MIME type "application/json-seq".
|
||||
pub const quirk_allow_leading_ascii_record_separator base.u32 = 0x4909_9400 | 0x0E
|
||||
pub const QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR base.u32 = 0x4909_9400 | 0x0E
|
||||
|
||||
// When this quirk is enabled, the input byte stream may optionally start with
|
||||
// "\xEF\xBB\xBF", the UTF-8 encoding of the Unicode BOM (Byte Order Mark).
|
||||
// Those 3 bytes are skipped and decoding proceeds normally.
|
||||
//
|
||||
// When combined with quirk_allow_leading_ascii_record_separator, either mark
|
||||
// When combined with QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR, either mark
|
||||
// may come first in the byte stream.
|
||||
pub const quirk_allow_leading_unicode_byte_order_mark base.u32 = 0x4909_9400 | 0x0F
|
||||
pub const QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK base.u32 = 0x4909_9400 | 0x0F
|
||||
|
||||
// When this quirk is enabled, following a successful decoding of a top-level
|
||||
// JSON value, any trailing whitespace (ASCII characters 0x09, 0x0A, 0x0D or
|
||||
@@ -178,16 +178,16 @@ pub const quirk_allow_leading_unicode_byte_order_mark base.u32 = 0x4909_9400 | 0
|
||||
// such bytes may confuse other line oriented Unix tools that assume exactly
|
||||
// one JSON value per line.
|
||||
//
|
||||
// When combined with quirk_allow_leading_ascii_record_separator, this format
|
||||
// When combined with QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR, this format
|
||||
// is also known as RFC 7464, Json Text Sequences and MIME type
|
||||
// "application/json-seq".
|
||||
//
|
||||
// When combined with quirk_allow_comment_block or quirk_allow_comment_line, it
|
||||
// When combined with QUIRK_ALLOW_COMMENT_BLOCK or QUIRK_ALLOW_COMMENT_LINE, it
|
||||
// is an error for a comment to occur in this trailing whitespace, before an
|
||||
// end-of-file or '\n' is encountered. Treating this as an error avoids any
|
||||
// ambiguity in accounting for new lines within a block comment or ending a
|
||||
// line comment.
|
||||
pub const quirk_allow_trailing_new_line base.u32 = 0x4909_9400 | 0x10
|
||||
pub const QUIRK_ALLOW_TRAILING_NEW_LINE base.u32 = 0x4909_9400 | 0x10
|
||||
|
||||
// When this quirk is enabled, invalid UTF-8 inside a JSON string is accepted.
|
||||
// Each byte of invalid UTF-8 is equivalent to "\uFFFD", the Unicode
|
||||
@@ -200,7 +200,7 @@ pub const quirk_allow_trailing_new_line base.u32 = 0x4909_9400 | 0x10
|
||||
// "abc\uDC00z" and "ijk\uD800\uDBFFz" are equivalent to "abc\uFFFDz" and
|
||||
// "ijk\uFFFD\uFFFDz".
|
||||
//
|
||||
// When combined with quirk_allow_backslash_capital_u, a "\U12345678" 10-byte
|
||||
// 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_unicode base.u32 = 0x4909_9400 | 0x11
|
||||
pub const QUIRK_REPLACE_INVALID_UNICODE base.u32 = 0x4909_9400 | 0x11
|
||||
Reference in new issue
Block a user