Skip to content

Commit f20f9e6

Browse files
committed
Fix handling of upper-case sigma (#124714)
1 parent 2be1083 commit f20f9e6

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

library/alloc/src/str.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,16 @@ impl str {
369369
pub fn to_lowercase(&self) -> String {
370370
let (mut s, rest) = convert_while_ascii(self, u8::to_ascii_lowercase);
371371

372+
let prefix_len = s.len();
373+
372374
for (i, c) in rest[..].char_indices() {
373375
if c == 'Σ' {
374376
// Σ maps to σ, except at the end of a word where it maps to ς.
375377
// This is the only conditional (contextual) but language-independent mapping
376378
// in `SpecialCasing.txt`,
377379
// so hard-code it rather than have a generic "condition" mechanism.
378380
// See https://github.com/rust-lang/rust/issues/26035
379-
map_uppercase_sigma(rest, i, &mut s)
381+
map_uppercase_sigma(self, prefix_len + i, &mut s)
380382
} else {
381383
match conversions::to_lower(c) {
382384
[a, '\0', _] => s.push(a),

library/alloc/tests/str.rs

+17
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,19 @@ fn to_lowercase() {
18261826
assert_eq!("Α'Σ".to_lowercase(), "α'ς");
18271827
assert_eq!("Α''Σ".to_lowercase(), "α''ς");
18281828

1829+
assert_eq!("aΣ".to_lowercase(), "aς");
1830+
assert_eq!("a'Σ".to_lowercase(), "a'ς");
1831+
assert_eq!("a''Σ".to_lowercase(), "a''ς");
1832+
1833+
assert_eq!("ÄΣ".to_lowercase(), "äς");
1834+
assert_eq!("ä'Σ".to_lowercase(), "ä'ς");
1835+
assert_eq!("ä''Σ".to_lowercase(), "ä''ς");
1836+
1837+
// input lengths around the boundary of the chunk size used by the ascii prefix optimization
1838+
assert_eq!("abcdefghijklmnoΣ".to_lowercase(), "abcdefghijklmnoς");
1839+
assert_eq!("abcdefghijklmnopΣ".to_lowercase(), "abcdefghijklmnopς");
1840+
assert_eq!("abcdefghijklmnopqΣ".to_lowercase(), "abcdefghijklmnopqς");
1841+
18291842
assert_eq!("ΑΣ Α".to_lowercase(), "ας α");
18301843
assert_eq!("Α'Σ Α".to_lowercase(), "α'ς α");
18311844
assert_eq!("Α''Σ Α".to_lowercase(), "α''ς α");
@@ -1840,6 +1853,10 @@ fn to_lowercase() {
18401853
assert_eq!("Α 'Σ".to_lowercase(), "α 'σ");
18411854
assert_eq!("Α ''Σ".to_lowercase(), "α ''σ");
18421855

1856+
assert_eq!("Ä Σ".to_lowercase(), "ä σ");
1857+
assert_eq!("Ä 'Σ".to_lowercase(), "ä 'σ");
1858+
assert_eq!("Ä ''Σ".to_lowercase(), "ä ''σ");
1859+
18431860
assert_eq!("Σ".to_lowercase(), "σ");
18441861
assert_eq!("'Σ".to_lowercase(), "'σ");
18451862
assert_eq!("''Σ".to_lowercase(), "''σ");

0 commit comments

Comments
 (0)