Address a review comment and fix a bootstrapping issue
This commit is contained in:
parent
7ac6b58237
commit
c57a4124ff
4 changed files with 37 additions and 6 deletions
|
@ -1856,6 +1856,11 @@ impl str {
|
|||
let mut s = String::with_capacity(self.len());
|
||||
for (i, c) in self[..].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" mechanim.
|
||||
// See https://github.com/rust-lang/rust/issues/26035
|
||||
map_uppercase_sigma(self, i, &mut s)
|
||||
} else {
|
||||
s.extend(c.to_lowercase());
|
||||
|
@ -1863,9 +1868,9 @@ impl str {
|
|||
}
|
||||
return s;
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn map_uppercase_sigma(from: &str, i: usize, to: &mut String) {
|
||||
// See http://www.unicode.org/versions/Unicode7.0.0/ch03.pdf#G33992
|
||||
// for the definition of `Final_Sigma`.
|
||||
debug_assert!('Σ'.len_utf8() == 2);
|
||||
let is_word_final =
|
||||
case_ignoreable_then_cased(from[..i].chars().rev()) &&
|
||||
|
|
|
@ -1690,8 +1690,34 @@ fn trim_ws() {
|
|||
#[test]
|
||||
fn to_lowercase() {
|
||||
assert_eq!("".to_lowercase(), "");
|
||||
assert_eq!("AÉDžaé ".to_lowercase(), "aédžaé ");
|
||||
|
||||
// https://github.com/rust-lang/rust/issues/26035
|
||||
assert_eq!("'Σ AÉΣ'Σ'' Σ DžΣ".to_lowercase(), "'σ aéσ'ς'' σ džς");
|
||||
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(), "ας'' α");
|
||||
|
||||
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(), "''σ");
|
||||
|
||||
assert_eq!("ΑΣΑ".to_lowercase(), "ασα");
|
||||
assert_eq!("ΑΣ'Α".to_lowercase(), "ασ'α");
|
||||
assert_eq!("ΑΣ''Α".to_lowercase(), "ασ''α");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
#![feature(box_patterns)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(collections)]
|
||||
#![cfg_attr(stage0, feature(collections))]
|
||||
#![feature(core)]
|
||||
#![feature(quote)]
|
||||
#![feature(rustc_diagnostic_macros)]
|
||||
|
|
|
@ -70,7 +70,7 @@ impl Iterator for ToUppercase {
|
|||
/// An iterator over the titlecase mapping of a given character, returned from
|
||||
/// the [`to_titlecase` method](../primitive.char.html#method.to_titlecase) on
|
||||
/// characters.
|
||||
#[stable(feature = "unicode_case_mapping", since = "1.2.0")]
|
||||
#[unstable(feature = "unicode", reason = "recently added")]
|
||||
pub struct ToTitlecase(CaseMappingIter);
|
||||
|
||||
#[stable(feature = "unicode_case_mapping", since = "1.2.0")]
|
||||
|
@ -481,7 +481,7 @@ impl char {
|
|||
/// Returns an iterator which yields the characters corresponding to the
|
||||
/// lowercase equivalent of the character. If no conversion is possible then
|
||||
/// an iterator with just the input character is returned.
|
||||
#[stable(feature = "unicode_case_mapping", since = "1.2.0")]
|
||||
#[unstable(feature = "unicode", reason = "recently added")]
|
||||
#[inline]
|
||||
pub fn to_titlecase(self) -> ToTitlecase {
|
||||
ToTitlecase(CaseMappingIter::new(conversions::to_title(self)))
|
||||
|
|
Loading…
Add table
Reference in a new issue