mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 16:32:11 +01:00
Have std/cbor parse text strings
This commit is contained in:
1 parent
3c8589b6e9
commit
d191a3fc5f
3 files changed
+198
-5
No files matched your search
+103
-3
@@ -156,7 +156,8 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
}} endwhile.goto_have_string_length
|
||||
}
|
||||
|
||||
if c_major == 0 { // Major type 0: an unsigned integer.
|
||||
if c_major == 0 {
|
||||
// -------- BEGIN Major type 0: an unsigned integer.
|
||||
if c_minor < 0x18 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
@@ -176,8 +177,10 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
length: 1 + ((1 as base.u32) << (c_minor - 0x18)))
|
||||
break.goto_parsed_a_leaf_value
|
||||
}
|
||||
// -------- END Major type 0: an unsigned integer.
|
||||
|
||||
} else if c_major == 1 { // Major type 1: a negative integer.
|
||||
} else if c_major == 1 {
|
||||
// -------- END Major type 1: a negative integer.
|
||||
if c_minor < 0x18 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
@@ -194,8 +197,10 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
length: 1 + ((1 as base.u32) << (c_minor - 0x18)))
|
||||
break.goto_parsed_a_leaf_value
|
||||
}
|
||||
// -------- END Major type 1: a negative integer.
|
||||
|
||||
} else if c_major == 2 { // Major type 2: a byte string.
|
||||
} else if c_major == 2 {
|
||||
// -------- BEGIN Major type 2: a byte string.
|
||||
if c_minor == 0x00 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
@@ -269,6 +274,101 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
}
|
||||
break.goto_parsed_a_leaf_value
|
||||
} endwhile
|
||||
// -------- END Major type 2: a byte string.
|
||||
|
||||
} else if c_major == 3 {
|
||||
// -------- BEGIN Major type 3: a text string.
|
||||
if c_minor == 0x00 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_ASCII |
|
||||
base.TOKEN__VBD__STRING__CONVERT_0_DST_1_SRC_DROP,
|
||||
continued: 0,
|
||||
length: 1)
|
||||
break.goto_parsed_a_leaf_value
|
||||
} else if c_minor < 0x18 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_ASCII |
|
||||
base.TOKEN__VBD__STRING__CONVERT_0_DST_1_SRC_DROP,
|
||||
continued: 1,
|
||||
length: 1)
|
||||
} else if c_minor < 0x1C {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_ASCII |
|
||||
base.TOKEN__VBD__STRING__CONVERT_0_DST_1_SRC_DROP,
|
||||
continued: 1,
|
||||
length: 1 + ((1 as base.u32) << (c_minor & 3)))
|
||||
} else if c_minor == 0x1F {
|
||||
indefinite_string_major_type = 3
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_ASCII |
|
||||
base.TOKEN__VBD__STRING__CONVERT_0_DST_1_SRC_DROP,
|
||||
continued: 1,
|
||||
length: 1)
|
||||
continue.outer
|
||||
} else {
|
||||
break.goto_fail
|
||||
}
|
||||
|
||||
while true {
|
||||
if args.dst.available() <= 0 {
|
||||
yield? base."$short write"
|
||||
continue
|
||||
}
|
||||
n64 = string_length.min(a: args.src.available())
|
||||
token_length = (n64 & 0xFFFF) as base.u32
|
||||
if n64 > 0xFFFF {
|
||||
token_length = 0xFFFF
|
||||
}
|
||||
// TODO: walk token_length back to a UTF-8 boundary.
|
||||
if token_length <= 0 {
|
||||
if args.src.is_closed() {
|
||||
return "#bad input"
|
||||
}
|
||||
yield? base."$short read"
|
||||
continue
|
||||
}
|
||||
if args.src.available() < (token_length as base.u64) {
|
||||
return "#internal error: inconsistent token length"
|
||||
}
|
||||
string_length ~mod-= token_length as base.u64
|
||||
continued = 0
|
||||
if (string_length > 0) or (indefinite_string_major_type > 0) {
|
||||
continued = 1
|
||||
}
|
||||
args.src.skip_u32_fast!(actual: token_length, worst_case: token_length)
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_ASCII |
|
||||
base.TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY,
|
||||
continued: continued,
|
||||
length: token_length)
|
||||
if string_length > 0 {
|
||||
continue
|
||||
} else if indefinite_string_major_type > 0 {
|
||||
continue.outer
|
||||
}
|
||||
break.goto_parsed_a_leaf_value
|
||||
} endwhile
|
||||
// -------- END Major type 3: a text string.
|
||||
}
|
||||
break.goto_fail
|
||||
}} endwhile.goto_fail
|
||||
|
||||
Reference in new issue
Block a user