Skip to content

Commit

Permalink
Fix handling of upper-case sigma (#124714)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhorstmann committed May 5, 2024
1 parent 2be1083 commit f20f9e6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion library/alloc/src/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,16 @@ impl str {
pub fn to_lowercase(&self) -> String {
let (mut s, rest) = convert_while_ascii(self, u8::to_ascii_lowercase);

let prefix_len = s.len();

for (i, c) in rest[..].char_indices() {
if c == 'Σ' {
// Σ maps to σ, except at the end of a word where it maps to ς.
// This is the only conditional (contextual) but language-independent mapping
// in `SpecialCasing.txt`,
// so hard-code it rather than have a generic "condition" mechanism.
// See https://github.com/rust-lang/rust/issues/26035
map_uppercase_sigma(rest, i, &mut s)
map_uppercase_sigma(self, prefix_len + i, &mut s)
} else {
match conversions::to_lower(c) {
[a, '\0', _] => s.push(a),
Expand Down
17 changes: 17 additions & 0 deletions library/alloc/tests/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1826,6 +1826,19 @@ fn to_lowercase() {
assert_eq!("Α'Σ".to_lowercase(), "α'ς");
assert_eq!("Α''Σ".to_lowercase(), "α''ς");

assert_eq!("aΣ".to_lowercase(), "aς");
assert_eq!("a'Σ".to_lowercase(), "a'ς");
assert_eq!("a''Σ".to_lowercase(), "a''ς");

assert_eq!("ÄΣ".to_lowercase(), "äς");
assert_eq!("ä'Σ".to_lowercase(), "ä'ς");
assert_eq!("ä''Σ".to_lowercase(), "ä''ς");

// input lengths around the boundary of the chunk size used by the ascii prefix optimization
assert_eq!("abcdefghijklmnoΣ".to_lowercase(), "abcdefghijklmnoς");
assert_eq!("abcdefghijklmnopΣ".to_lowercase(), "abcdefghijklmnopς");
assert_eq!("abcdefghijklmnopqΣ".to_lowercase(), "abcdefghijklmnopqς");

assert_eq!("ΑΣ Α".to_lowercase(), "ας α");
assert_eq!("Α'Σ Α".to_lowercase(), "α'ς α");
assert_eq!("Α''Σ Α".to_lowercase(), "α''ς α");
Expand All @@ -1840,6 +1853,10 @@ fn to_lowercase() {
assert_eq!("Α 'Σ".to_lowercase(), "α 'σ");
assert_eq!("Α ''Σ".to_lowercase(), "α ''σ");

assert_eq!("Ä Σ".to_lowercase(), "ä σ");
assert_eq!("Ä 'Σ".to_lowercase(), "ä 'σ");
assert_eq!("Ä ''Σ".to_lowercase(), "ä ''σ");

assert_eq!("Σ".to_lowercase(), "σ");
assert_eq!("'Σ".to_lowercase(), "'σ");
assert_eq!("''Σ".to_lowercase(), "''σ");
Expand Down

0 comments on commit f20f9e6

Please sign in to comment.