fix: utf16 len fallback to utf8 when unknown (#93)

This commit is contained in:
Zixuan Chen 2023-04-04 17:28:35 +08:00 committed by GitHub
parent 3e64116621
commit bbcb6f3957
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View file

@ -51,9 +51,21 @@ impl Rope {
index,
|x| x.utf8 as usize,
|x| x.atom_len(),
|x| x.utf16 as usize,
|x| x.utf16_length as usize,
|s, src_offset| s.utf8_index_to_utf16(src_offset).unwrap_or(0),
|x| {
if x.unknown_elem_len != 0 {
x.utf8 as usize
} else {
x.utf16 as usize
}
},
|x| {
if x.slice.is_some() {
x.utf16_length as usize
} else {
x.unknown_len as usize
}
},
|s, src_offset| s.utf8_index_to_utf16(src_offset).unwrap_or(src_offset),
)
}

View file

@ -82,7 +82,6 @@ impl Meta for Utf16Meta {
utf16_len
);
*utf16_len -= other_len;
debug_assert_ne!(*utf16_len, 0);
}
*other