mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 16:47:28 +01:00
Add single-quoted strings
This commit is contained in:
1 parent
3bfed6d812
commit
9e50918718
14 files changed
+273
-84
No files matched your search
+29
-29
@@ -361,7 +361,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
continue.string_loop_outer
|
||||
}
|
||||
|
||||
} else if c == 0x75 { // 0x75 is 'u'.
|
||||
} else if c == 'u' {
|
||||
// -------- BEGIN backslash-u.
|
||||
if args.src.available() < 6 {
|
||||
if args.src.is_closed() {
|
||||
@@ -437,8 +437,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
uni4_string = args.src.peek_u64le_at(offset: 4) >> 16
|
||||
|
||||
// Look for the low surrogate's "\\u".
|
||||
if ((0xFF & (uni4_string >> 0)) <> 0x5C) or
|
||||
((0xFF & (uni4_string >> 8)) <> 0x75) {
|
||||
if ((0xFF & (uni4_string >> 0)) <> '\\') or
|
||||
((0xFF & (uni4_string >> 8)) <> 'u') {
|
||||
uni4_high_surrogate = 0
|
||||
uni4_value = 0
|
||||
uni4_ok = 0
|
||||
@@ -492,8 +492,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
// -------- END backslash-u.
|
||||
|
||||
} else if (c == 0x55) and
|
||||
this.quirk_enabled_allow_backslash_capital_u { // 0x55 is 'U'.
|
||||
} else if (c == 'U') and
|
||||
this.quirk_enabled_allow_backslash_capital_u {
|
||||
// -------- BEGIN backslash-capital-u.
|
||||
if args.src.available() < 10 {
|
||||
if args.src.is_closed() {
|
||||
@@ -559,8 +559,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
// -------- END backslash-capital-u.
|
||||
|
||||
} else if (c == 0x78) and
|
||||
this.quirk_enabled_allow_backslash_x { // 0x78 is 'x'.
|
||||
} else if (c == 'x') and
|
||||
this.quirk_enabled_allow_backslash_x {
|
||||
// -------- BEGIN backslash-x
|
||||
if args.src.available() < 4 {
|
||||
if args.src.is_closed() {
|
||||
@@ -1030,7 +1030,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
continue.outer
|
||||
|
||||
} else if class == 0x09 { // 0x09 is CLASS_FALSE.
|
||||
match = args.src.match7(a: 0x6573_6C61_6605) // 5 bytes "false".
|
||||
match = args.src.match7(a: '\x05false'le)
|
||||
if match == 0 {
|
||||
args.dst.write_fast_token!(
|
||||
value_major: 0,
|
||||
@@ -1048,7 +1048,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
|
||||
} else if class == 0x0A { // 0x0A is CLASS_TRUE.
|
||||
match = args.src.match7(a: 0x65_7572_7404) // 4 bytes "true".
|
||||
match = args.src.match7(a: '\x04true'le)
|
||||
if match == 0 {
|
||||
args.dst.write_fast_token!(
|
||||
value_major: 0,
|
||||
@@ -1066,7 +1066,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
|
||||
} else if class == 0x0B { // 0x0B is CLASS_NULL_NAN_INF.
|
||||
match = args.src.match7(a: 0x6C_6C75_6E04) // 4 bytes "null".
|
||||
match = args.src.match7(a: '\x04null'le)
|
||||
if match == 0 {
|
||||
args.dst.write_fast_token!(
|
||||
value_major: 0,
|
||||
@@ -1131,7 +1131,7 @@ pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
||||
c = args.src.peek_u8()
|
||||
|
||||
// Scan the optional minus sign.
|
||||
if c <> 0x2D { // 0x2D is '-'.
|
||||
if c <> '-' {
|
||||
assert args.src.available() > 0
|
||||
assert n <= 1
|
||||
} else {
|
||||
@@ -1153,7 +1153,7 @@ pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
||||
}
|
||||
|
||||
// Scan the opening digits.
|
||||
if c == 0x30 { // 0x30 is '0'.
|
||||
if c == '0' {
|
||||
n += 1
|
||||
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||
assert n <= 99
|
||||
@@ -1175,7 +1175,7 @@ pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
||||
c = args.src.peek_u8()
|
||||
|
||||
// Scan the optional fraction.
|
||||
if c <> 0x2E { // 0x2E is '.'.
|
||||
if c <> '.' {
|
||||
assert args.src.available() > 0
|
||||
assert n <= 99
|
||||
} else {
|
||||
@@ -1206,7 +1206,7 @@ pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
||||
}
|
||||
|
||||
// Scan the optional 'E' or 'e'.
|
||||
if (c <> 0x45) and (c <> 0x65) { // 0x45 and 0x65 are 'E' and 'e'.
|
||||
if (c <> 'E') and (c <> 'e') {
|
||||
break.goto_done
|
||||
}
|
||||
if n >= 99 {
|
||||
@@ -1229,7 +1229,7 @@ pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
||||
c = args.src.peek_u8()
|
||||
|
||||
// Scan the optional '+' or '-'.
|
||||
if (c <> 0x2B) and (c <> 0x2D) { // 0x2B and 0x2D are '+' and '-'.
|
||||
if (c <> '+') and (c <> '-') {
|
||||
assert n <= 99
|
||||
} else {
|
||||
if n >= 99 {
|
||||
@@ -1354,7 +1354,7 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
c2 = args.src.peek_u16le()
|
||||
|
||||
if (c2 == 0x2A2F) and this.quirk_enabled_allow_comment_block {
|
||||
if (c2 == '/*'le) and this.quirk_enabled_allow_comment_block {
|
||||
args.src.skip32_fast!(actual: 2, worst_case: 2)
|
||||
length = 2
|
||||
|
||||
@@ -1386,7 +1386,7 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
|
||||
c2 = args.src.peek_u16le()
|
||||
if c2 == 0x2F2A { // 0x2F2A is "*/" little-endian.
|
||||
if c2 == '*/'le {
|
||||
args.src.skip32_fast!(actual: 2, worst_case: 2)
|
||||
args.dst.write_fast_token!(
|
||||
value_major: 0,
|
||||
@@ -1411,7 +1411,7 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
} endwhile.comment_block
|
||||
|
||||
} else if (c2 == 0x2F2F) and this.quirk_enabled_allow_comment_line {
|
||||
} else if (c2 == '//'le) and this.quirk_enabled_allow_comment_line {
|
||||
args.src.skip32_fast!(actual: 2, worst_case: 2)
|
||||
length = 2
|
||||
|
||||
@@ -1443,7 +1443,7 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
|
||||
c = args.src.peek_u8()
|
||||
if c == 0x0A { // 0x0A is '\n'.
|
||||
if c == '\n' {
|
||||
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||
args.dst.write_fast_token!(
|
||||
value_major: 0,
|
||||
@@ -1492,9 +1492,9 @@ pri func decoder.decode_inf_nan?(dst: base.token_writer, src: base.io_reader) {
|
||||
// Bitwise or'ing with 0x20 converts upper case ASCII to lower case.
|
||||
|
||||
c4 = args.src.peek_u24le_as_u32()
|
||||
if (c4 | 0x20_2020) == 0x66_6E69 {
|
||||
if (c4 | 0x20_2020) == 'inf'le {
|
||||
if args.src.available() > 7 {
|
||||
if (args.src.peek_u64le() | 0x2020_2020_2020_2020) == 0x7974_696E_6966_6E69 {
|
||||
if (args.src.peek_u64le() | 0x2020_2020_2020_2020) == 'infinity'le {
|
||||
args.dst.write_fast_token!(
|
||||
value_major: 0,
|
||||
value_minor: 0xA0_0020,
|
||||
@@ -1515,7 +1515,7 @@ pri func decoder.decode_inf_nan?(dst: base.token_writer, src: base.io_reader) {
|
||||
args.src.skip32_fast!(actual: 3, worst_case: 3)
|
||||
return ok
|
||||
|
||||
} else if (c4 | 0x20_2020) == 0x6E_616E {
|
||||
} else if (c4 | 0x20_2020) == 'nan'le {
|
||||
args.dst.write_fast_token!(
|
||||
value_major: 0,
|
||||
value_minor: 0xA0_0080,
|
||||
@@ -1523,9 +1523,9 @@ pri func decoder.decode_inf_nan?(dst: base.token_writer, src: base.io_reader) {
|
||||
length: 3)
|
||||
args.src.skip32_fast!(actual: 3, worst_case: 3)
|
||||
return ok
|
||||
} else if (c4 & 0xFF) == 0x2B { // 0x2B is '+'.
|
||||
} else if (c4 & 0xFF) == '+' {
|
||||
neg = 0
|
||||
} else if (c4 & 0xFF) == 0x2D { // 0x2D is '-'.
|
||||
} else if (c4 & 0xFF) == '-' {
|
||||
neg = 1
|
||||
} else {
|
||||
return "#bad input"
|
||||
@@ -1540,9 +1540,9 @@ pri func decoder.decode_inf_nan?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
|
||||
c4 = args.src.peek_u32le() >> 8
|
||||
if (c4 | 0x20_2020) == 0x66_6E69 {
|
||||
if (c4 | 0x20_2020) == 'inf'le {
|
||||
if args.src.available() > 8 {
|
||||
if (args.src.peek_u64le_at(offset: 1) | 0x2020_2020_2020_2020) == 0x7974_696E_6966_6E69 {
|
||||
if (args.src.peek_u64le_at(offset: 1) | 0x2020_2020_2020_2020) == 'infinity'le {
|
||||
args.dst.write_fast_token!(
|
||||
value_major: 0,
|
||||
value_minor: 0xA0_0000 | ((0x20 as base.u32) >> neg),
|
||||
@@ -1563,7 +1563,7 @@ pri func decoder.decode_inf_nan?(dst: base.token_writer, src: base.io_reader) {
|
||||
args.src.skip32_fast!(actual: 4, worst_case: 4)
|
||||
return ok
|
||||
|
||||
} else if (c4 | 0x20_2020) == 0x6E_616E {
|
||||
} else if (c4 | 0x20_2020) == 'nan'le {
|
||||
args.dst.write_fast_token!(
|
||||
value_major: 0,
|
||||
value_minor: 0xA0_0000 | ((0x80 as base.u32) >> neg),
|
||||
@@ -1616,11 +1616,11 @@ pri func decoder.decode_trailing_new_line?(dst: base.token_writer, src: base.io_
|
||||
}
|
||||
|
||||
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||
if (whitespace_length >= 0xFFFE) or (c == 0x0A) {
|
||||
if (whitespace_length >= 0xFFFE) or (c == '\n') {
|
||||
args.dst.write_fast_token!(
|
||||
value_major: 0, value_minor: 0, link: 0x0, length: whitespace_length + 1)
|
||||
whitespace_length = 0
|
||||
if c == 0x0A {
|
||||
if c == '\n' {
|
||||
break.outer
|
||||
}
|
||||
continue.outer
|
||||
|
||||
Reference in new issue
Block a user