0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-12-23 15:50:11 -05:00

8-bit StringView uses latin-1 encoding, not UTF-8 (#237)

This commit is contained in:
Bert Belder 2020-01-21 23:58:17 +01:00
parent 4b8573a993
commit 9124720c5a
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461

View file

@ -158,7 +158,14 @@ unsafe impl<'a, T> Sync for CharacterArray<'a, T> where T: Sync {}
impl fmt::Display for CharacterArray<'_, u8> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&string::String::from_utf8_lossy(&*self))
f.write_str(
self
.iter()
.cloned()
.map(char::from)
.collect::<string::String>()
.as_str(),
)
}
}
@ -225,4 +232,5 @@ fn string_view_display() {
let ok: [u16; 2] = [111, 107];
assert_eq!("ok", format!("{}", StringView::from(&ok[..])));
assert_eq!("ok", format!("{}", StringView::from(&b"ok"[..])));
assert_eq!("ØÞ", format!("{}", StringView::from(&[216u8, 222u8][..])));
}