Skip to content

Commit

Permalink
Handle array manually in string case conversion methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Pazzaz committed Jul 6, 2018
1 parent 4faaf7e commit ad7621d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/liballoc/str.rs
Expand Up @@ -45,6 +45,7 @@ use core::str::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher};
use core::mem;
use core::ptr;
use core::iter::FusedIterator;
use core::unicode::conversions;

use borrow::{Borrow, ToOwned};
use boxed::Box;
Expand Down Expand Up @@ -369,7 +370,18 @@ impl str {
// See https://github.com/rust-lang/rust/issues/26035
map_uppercase_sigma(self, i, &mut s)
} else {
s.extend(c.to_lowercase());
match conversions::to_lower(c) {
[a, '\0', _] => s.push(a),
[a, b, '\0'] => {
s.push(a);
s.push(b);
}
[a, b, c] => {
s.push(a);
s.push(b);
s.push(c);
}
}
}
}
return s;
Expand Down Expand Up @@ -423,7 +435,20 @@ impl str {
#[stable(feature = "unicode_case_mapping", since = "1.2.0")]
pub fn to_uppercase(&self) -> String {
let mut s = String::with_capacity(self.len());
s.extend(self.chars().flat_map(|c| c.to_uppercase()));
for c in self[..].chars() {
match conversions::to_upper(c) {
[a, '\0', _] => s.push(a),
[a, b, '\0'] => {
s.push(a);
s.push(b);
}
[a, b, c] => {
s.push(a);
s.push(b);
s.push(c);
}
}
}
return s;
}

Expand Down
3 changes: 3 additions & 0 deletions src/libcore/unicode/mod.rs
Expand Up @@ -20,6 +20,9 @@ pub(crate) mod version;
pub mod derived_property {
pub use unicode::tables::derived_property::{Case_Ignorable, Cased};
}
pub mod conversions {
pub use unicode::tables::conversions::{to_lower, to_upper};
}

// For use in libsyntax
pub mod property {
Expand Down

0 comments on commit ad7621d

Please sign in to comment.