From 0f6a0b58f9dbc3a741abd898f2d06a8ba78a938d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 5 Mar 2015 18:23:57 -0800 Subject: std: Stabilize more of the `char` module This commit performs another pass over the `std::char` module for stabilization. Some minor cleanup is performed such as migrating documentation from libcore to libunicode (where the `std`-facing trait resides) as well as a slight reorganiation in libunicode itself. Otherwise, the stability modifications made are: * `char::from_digit` is now stable * `CharExt::is_digit` is now stable * `CharExt::to_digit` is now stable * `CharExt::to_{lower,upper}case` are now stable after being modified to return an iterator over characters. While the implementation today has not changed this should allow us to implement the full set of case conversions in unicode where some characters can map to multiple when doing an upper or lower case mapping. * `StrExt::to_{lower,upper}case` was added as unstable for a convenience of not having to worry about characters expanding to more characters when you just want the whole string to get into upper or lower case. This is a breaking change due to the change in the signatures of the `CharExt::to_{upper,lower}case` methods. Code can be updated to use functions like `flat_map` or `collect` to handle the difference. [breaking-change] --- src/libstd/old_io/mod.rs | 3 +-- src/libstd/old_io/process.rs | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/old_io/mod.rs b/src/libstd/old_io/mod.rs index 9ce888efceb..f2042b384ce 100644 --- a/src/libstd/old_io/mod.rs +++ b/src/libstd/old_io/mod.rs @@ -343,8 +343,7 @@ impl IoError { pub fn from_errno(errno: i32, detail: bool) -> IoError { let mut err = sys::decode_error(errno as i32); if detail && err.kind == OtherIoError { - err.detail = Some(os::error_string(errno).chars() - .map(|c| c.to_lowercase()).collect()) + err.detail = Some(os::error_string(errno).to_lowercase()); } err } diff --git a/src/libstd/old_io/process.rs b/src/libstd/old_io/process.rs index e02e863516a..a30dcd9d9f0 100644 --- a/src/libstd/old_io/process.rs +++ b/src/libstd/old_io/process.rs @@ -110,10 +110,11 @@ struct EnvKey(CString); #[cfg(windows)] impl hash::Hash for EnvKey { fn hash(&self, state: &mut H) { + use ascii::AsciiExt; let &EnvKey(ref x) = self; match str::from_utf8(x.as_bytes()) { Ok(s) => for ch in s.chars() { - (ch as u8 as char).to_lowercase().hash(state); + ch.to_ascii_lowercase().hash(state); }, Err(..) => x.hash(state) } @@ -123,6 +124,7 @@ impl hash::Hash for EnvKey { #[cfg(windows)] impl PartialEq for EnvKey { fn eq(&self, other: &EnvKey) -> bool { + use ascii::AsciiExt; let &EnvKey(ref x) = self; let &EnvKey(ref y) = other; match (str::from_utf8(x.as_bytes()), str::from_utf8(y.as_bytes())) { @@ -131,7 +133,7 @@ impl PartialEq for EnvKey { return false } else { for (xch, ych) in xs.chars().zip(ys.chars()) { - if xch.to_lowercase() != ych.to_lowercase() { + if xch.to_ascii_lowercase() != ych.to_ascii_lowercase() { return false; } } -- cgit 1.4.1-3-g733a5