Map ASCII case without ICU in simple_lowercase/simple_uppercase (#8833)

Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
1ndahous3 authored and GitHub committed 2026-09-26 21:45:15 +09:00
1 parent 622e9252c2
commit c5b128a4cb
1 file changed
+15
+15
View File
@@ -33,12 +33,18 @@ use writeable::Writeable;
/// Simple (one-to-one) lowercase mapping of `c` (`Py_UNICODE_TOLOWER`).
#[must_use]
pub fn simple_lowercase(c: char) -> char {
if c.is_ascii() {
return c.to_ascii_lowercase();
}
CaseMapper::new().simple_lowercase(c)
}
/// Simple (one-to-one) uppercase mapping of `c` (`Py_UNICODE_TOUPPER`).
#[must_use]
pub fn simple_uppercase(c: char) -> char {
if c.is_ascii() {
return c.to_ascii_uppercase();
}
CaseMapper::new().simple_uppercase(c)
}
@@ -379,6 +385,15 @@ mod tests {
assert_eq!(capitalize_str("ßhello"), "Sshello");
}
#[test]
fn ascii_fast_path_matches_icu() {
let mapper = icu_casemap::CaseMapper::new();
for c in (0u8..0x80).map(char::from) {
assert_eq!(simple_lowercase(c), mapper.simple_lowercase(c));
assert_eq!(simple_uppercase(c), mapper.simple_uppercase(c));
}
}
#[test]
fn wtf8_passes_surrogates_through() {
let mut buf = Wtf8Buf::from("ab cd");