about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorPazzaz <pazzaz.sundqvist@gmail.com>2018-07-06 17:20:39 +0200
committerPazzaz <pazzaz.sundqvist@gmail.com>2018-07-06 17:20:39 +0200
commitad7621d42ee90143cd15715cc546177575fd5844 (patch)
tree21c70c59f3eb5d0ebea472e0339f35fd3c3361cc /src/liballoc
parent4faaf7e3359fa78bad2e8c54011e94ce8ac078c6 (diff)
downloadrust-ad7621d42ee90143cd15715cc546177575fd5844.tar.gz
rust-ad7621d42ee90143cd15715cc546177575fd5844.zip
Handle array manually in string case conversion methods
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/str.rs29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs
index bb99d0401d3..4d6434c378e 100644
--- a/src/liballoc/str.rs
+++ b/src/liballoc/str.rs
@@ -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;
@@ -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;
@@ -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;
     }