mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 00:47:28 +01:00
Add std/json character classes
This commit is contained in:
1 parent
9263c80cfb
commit
48e7004636
3 files changed
+116
-40
No files matched your search
+15
-19
@@ -57,6 +57,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
var stack_bit : base.u32[..= 31]
|
||||
var match : base.u32[..= 2]
|
||||
var c : base.u8
|
||||
var class : base.u8[..= 0x0F]
|
||||
var backslash : base.u8
|
||||
var uni4_ok : base.u8
|
||||
var uni4_string : base.u32
|
||||
@@ -96,6 +97,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
// Consume whitespace.
|
||||
whitespace_length = 0
|
||||
c = 0
|
||||
class = 0
|
||||
while.ws true,
|
||||
inv args.dst.available() > 0,
|
||||
post args.src.available() > 0,
|
||||
@@ -116,15 +118,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
|
||||
c = args.src.peek_u8()
|
||||
if c > 0x20 { // 0x20 is ' '.
|
||||
class = classes[c]
|
||||
if class <> 0x00 { // 0x00 is CLASS_WHITESPACE.
|
||||
break.ws
|
||||
} else if (c <> 0x20) and (c <> 0x0A) and (c <> 0x09) and (c <> 0x0D) {
|
||||
if whitespace_length > 0 {
|
||||
args.dst.write_fast_token!(
|
||||
value: 0,
|
||||
length: whitespace_length as base.u64)
|
||||
}
|
||||
return "#bad input"
|
||||
}
|
||||
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||
|
||||
@@ -157,7 +153,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
assert args.src.available() > 0
|
||||
|
||||
if c <= 0x39 { // 0x39 is '9'.
|
||||
if c == 0x22 { // 0x22 is '"'.
|
||||
if class == 0x01 { // 0x01 is CLASS_STRING.
|
||||
// -------- BEGIN parse strings.
|
||||
if 0 == (expect & 0x02) { // 0x02 is EXPECT_STRING_VALUE.
|
||||
return "#bad input"
|
||||
@@ -333,7 +329,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
break.goto_parsed_a_leaf_value
|
||||
// -------- END parse strings.
|
||||
|
||||
} else if c == 0x2C { // 0x2C is ','.
|
||||
} else if class == 0x02 { // 0x02 is CLASS_COMMA.
|
||||
if 0 == (expect & 0x04) { // 0x01 is EXPECT_COMMA.
|
||||
return "#bad input"
|
||||
}
|
||||
@@ -351,7 +347,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
continue.outer
|
||||
|
||||
} else if (c >= 0x30) or (c == 0x2D) { // 0x30 is '0', 0x2D is '-'.
|
||||
} else if class == 0x04 { // 0x04 is CLASS_NUMBER.
|
||||
// -------- BEGIN parse numbers.
|
||||
if 0 == (expect & 0x01) { // 0x02 is EXPECT_NON_STRING_VALUE.
|
||||
return "#bad input"
|
||||
@@ -399,7 +395,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
// -------- END parse numbers.
|
||||
}
|
||||
|
||||
} else if c == 0x3A { // 0x3A is ':'.
|
||||
} else if class == 0x03 { // 0x03 is CLASS_COLON.
|
||||
if 0 == (expect & 0x08) { // 0x08 is EXPECT_COLON.
|
||||
return "#bad input"
|
||||
}
|
||||
@@ -411,7 +407,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
expect = 0x03 // 0x03 is EXPECT_VALUE.
|
||||
continue.outer
|
||||
|
||||
} else if c == 0x5B { // 0x5B is '['.
|
||||
} else if class == 0x07 { // 0x07 is CLASS_OPEN_SQUARE_BRACKET.
|
||||
if 0 == (expect & 0x01) { // 0x01 is EXPECT_NON_STRING_VALUE.
|
||||
return "#bad input"
|
||||
}
|
||||
@@ -431,7 +427,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
expect_after_value = 0x14 // 0x14 is (EXPECT_CLOSE_BRACKET | EXPECT_COMMA).
|
||||
continue.outer
|
||||
|
||||
} else if c == 0x5D { // 0x5D is ']'.
|
||||
} else if class == 0x08 { // 0x08 is CLASS_CLOSE_SQUARE_BRACKET.
|
||||
if 0 == (expect & 0x10) { // 0x10 is EXPECT_CLOSE_BRACKET
|
||||
return "#bad input"
|
||||
}
|
||||
@@ -462,7 +458,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
continue.outer
|
||||
|
||||
} else if c == 0x7B { // 0x7B is '{'.
|
||||
} else if class == 0x05 { // 0x05 is CLASS_OPEN_CURLY_BRACE.
|
||||
if 0 == (expect & 0x01) { // 0x01 is EXPECT_NON_STRING_VALUE.
|
||||
return "#bad input"
|
||||
}
|
||||
@@ -482,7 +478,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
expect_after_value = 0x24 // 0x24 is (EXPECT_CLOSE_BRACE | EXPECT_COMMA).
|
||||
continue.outer
|
||||
|
||||
} else if c == 0x7D { // 0x7D is '}'.
|
||||
} else if class == 0x06 { // 0x06 is CLASS_CLOSE_CURLY_BRACE.
|
||||
if 0 == (expect & 0x20) { // 0x20 is EXPECT_CLOSE_BRACE.
|
||||
return "#bad input"
|
||||
}
|
||||
@@ -518,7 +514,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
return "#bad input"
|
||||
}
|
||||
match = 2
|
||||
if c == 0x6E { // 0x6E is 'n'.
|
||||
if class == 0x0B { // 0x0B is CLASS_NULL.
|
||||
match = args.src.match7(a: 0x6C_6C75_6E04) // 4 bytes "null".
|
||||
if match == 0 {
|
||||
args.dst.write_fast_token!(
|
||||
@@ -531,7 +527,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
break.goto_parsed_a_leaf_value
|
||||
}
|
||||
|
||||
} else if c == 0x66 { // 0x66 is 'f'.
|
||||
} else if class == 0x09 { // 0x09 is CLASS_FALSE.
|
||||
match = args.src.match7(a: 0x6573_6C61_6605) // 5 bytes "false".
|
||||
if match == 0 {
|
||||
args.dst.write_fast_token!(
|
||||
@@ -544,7 +540,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
break.goto_parsed_a_leaf_value
|
||||
}
|
||||
|
||||
} else if c == 0x74 { // 0x74 is 't'.
|
||||
} else if class == 0x0A { // 0x0A is CLASS_TRUE.
|
||||
match = args.src.match7(a: 0x65_7572_7404) // 4 bytes "true".
|
||||
if match == 0 {
|
||||
args.dst.write_fast_token!(
|
||||
|
||||
Reference in new issue
Block a user