mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Return character counts from the UTF-8 encoder fast path (#9205)
Assisted-by: Codex:GPT-6
This commit is contained in:
1 parent
3a0ef4d3d4
commit
65f30fd151
2 files changed
+5
-1
No files matched your search
@@ -241,7 +241,7 @@ mod _codecs {
|
||||
.as_ref()
|
||||
.is_some_and(|s| s.is(identifier!(vm, surrogatepass)))
|
||||
{
|
||||
return Ok((args.str.as_bytes().to_vec(), args.str.byte_len()));
|
||||
return Ok((args.str.as_bytes().to_vec(), args.str.char_len()));
|
||||
}
|
||||
do_codec!(utf8::encode, args, vm)
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ assert b"+-".decode("utf-7") == "+"
|
||||
|
||||
import _codecs
|
||||
|
||||
# Encoder counts are characters consumed, not the size of the encoded bytes.
|
||||
assert _codecs.utf_8_encode("é😀") == (b"\xc3\xa9\xf0\x9f\x98\x80", 2)
|
||||
assert _codecs.utf_8_encode("a\ud800b", "surrogatepass") == (b"a\xed\xa0\x80b", 3)
|
||||
|
||||
assert _codecs.escape_encode(b"a\tb") == (b"a\\tb", 3)
|
||||
assert _codecs.escape_decode(rb"a\tb") == (b"a\tb", 4)
|
||||
assert _codecs.utf_16_ex_decode(b"\xff\xfeh\x00i\x00", "strict", 0, True)[0] == "hi"
|
||||
|
||||
Reference in new issue
Block a user