Add single-quoted strings

This commit is contained in:
Nigel Tao committed 2020-03-25 19:41:02 +11:00
1 parent 3bfed6d812
commit 9e50918718
14 files changed
+273 -84

No files matched your search

+1 -1
View File
@@ -70,7 +70,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
// Read the BITMAPFILEHEADER (14 bytes).
magic = args.src.read_u16le_as_u32?()
if magic <> 0x4D42 { // "BM" little-endian.
if magic <> 'BM'le {
return "#bad header"
}
+7 -7
View File
@@ -180,9 +180,9 @@ pub func config_decoder.decode_image_config?(dst: nptr base.image_config, src: b
}
pub func config_decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
if args.fourcc == 0x4943_4350 { // "ICCP"
if args.fourcc == 'ICCP'be {
this.report_metadata_iccp = args.report
} else if args.fourcc == 0x584D_5020 { // "XMP "
} else if args.fourcc == 'XMP 'be {
this.report_metadata_xmp = args.report
}
}
@@ -204,7 +204,7 @@ pub func config_decoder.ack_metadata_chunk?(src: base.io_reader) {
this.metadata_chunk_length_value = args.src.peek_u8_as_u64()
if this.metadata_chunk_length_value > 0 {
if this.metadata_fourcc_value == 0x584D_5020 { // "XMP "
if this.metadata_fourcc_value == 'XMP 'be {
// The +1 is because XMP metadata's encoding includes each
// block's leading byte (the block size) as part of the
// metadata passed to the caller.
@@ -427,8 +427,8 @@ pri func config_decoder.decode_header?(src: base.io_reader) {
c[i] = args.src.read_u8?()
i += 1
}
if (c[0] <> 0x47) or (c[1] <> 0x49) or (c[2] <> 0x46) or (c[3] <> 0x38) or
((c[4] <> 0x37) and (c[4] <> 0x39)) or (c[5] <> 0x61) {
if (c[0] <> 'G') or (c[1] <> 'I') or (c[2] <> 'F') or (c[3] <> '8') or
((c[4] <> '7') and (c[4] <> '9')) or (c[5] <> 'a') {
return "#bad header"
}
}
@@ -617,7 +617,7 @@ pri func config_decoder.decode_ae?(src: base.io_reader) {
}
this.metadata_chunk_length_value = args.src.peek_u8_as_u64()
args.src.skip32_fast!(actual: 1, worst_case: 1)
this.metadata_fourcc_value = 0x4943_4350 // "ICCP"
this.metadata_fourcc_value = 'ICCP'be
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
this.call_sequence = 1
return base."@metadata reported"
@@ -637,7 +637,7 @@ pri func config_decoder.decode_ae?(src: base.io_reader) {
} else {
args.src.skip32_fast!(actual: 1, worst_case: 1)
}
this.metadata_fourcc_value = 0x584D_5020 // "XMP "
this.metadata_fourcc_value = 'XMP 'be
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
this.call_sequence = 1
return base."@metadata reported"
+7 -7
View File
@@ -219,9 +219,9 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
}
pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
if args.fourcc == 0x4943_4350 { // "ICCP"
if args.fourcc == 'ICCP'be {
this.report_metadata_iccp = args.report
} else if args.fourcc == 0x584D_5020 { // "XMP "
} else if args.fourcc == 'XMP 'be {
this.report_metadata_xmp = args.report
}
}
@@ -243,7 +243,7 @@ pub func decoder.ack_metadata_chunk?(src: base.io_reader) {
this.metadata_chunk_length_value = args.src.peek_u8_as_u64()
if this.metadata_chunk_length_value > 0 {
if this.metadata_fourcc_value == 0x584D_5020 { // "XMP "
if this.metadata_fourcc_value == 'XMP 'be {
// The +1 is because XMP metadata's encoding includes each
// block's leading byte (the block size) as part of the
// metadata passed to the caller.
@@ -502,8 +502,8 @@ pri func decoder.decode_header?(src: base.io_reader) {
c[i] = args.src.read_u8?()
i += 1
}
if (c[0] <> 0x47) or (c[1] <> 0x49) or (c[2] <> 0x46) or (c[3] <> 0x38) or
((c[4] <> 0x37) and (c[4] <> 0x39)) or (c[5] <> 0x61) {
if (c[0] <> 'G') or (c[1] <> 'I') or (c[2] <> 'F') or (c[3] <> '8') or
((c[4] <> '7') and (c[4] <> '9')) or (c[5] <> 'a') {
return "#bad header"
}
}
@@ -692,7 +692,7 @@ pri func decoder.decode_ae?(src: base.io_reader) {
}
this.metadata_chunk_length_value = args.src.peek_u8_as_u64()
args.src.skip32_fast!(actual: 1, worst_case: 1)
this.metadata_fourcc_value = 0x4943_4350 // "ICCP"
this.metadata_fourcc_value = 'ICCP'be
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
this.call_sequence = 1
return base."@metadata reported"
@@ -712,7 +712,7 @@ pri func decoder.decode_ae?(src: base.io_reader) {
} else {
args.src.skip32_fast!(actual: 1, worst_case: 1)
}
this.metadata_fourcc_value = 0x584D_5020 // "XMP "
this.metadata_fourcc_value = 'XMP 'be
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
this.call_sequence = 1
return base."@metadata reported"
+29 -29
View File
@@ -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