diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 81190ea8fc6..6d38d72e3f6 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -159,6 +159,9 @@ pub mod vec; pub mod at_vec; pub mod str; +#[path = "str/ascii.rs"] +pub mod ascii; + pub mod ptr; pub mod owned; pub mod managed; diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index 84793694582..fb4f9188b3b 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -40,11 +40,7 @@ pub use path::Path; pub use path::PosixPath; pub use path::WindowsPath; pub use ptr::Ptr; -// NOTE: Remove markers after snapshot -#[cfg(stage1)] -#[cfg(stage2)] -#[cfg(stage3)] -pub use str::{Ascii, AsciiCast, OwnedAsciiCast, ToStrAscii}; +pub use ascii::{Ascii, AsciiCast, OwnedAsciiCast, AsciiStr}; pub use str::{StrSlice, OwnedStr}; pub use to_bytes::IterBytes; pub use to_str::{ToStr, ToStrConsume}; diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 11301c9f1db..dc97af22c47 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -17,12 +17,6 @@ * some heavy-duty uses, try std::rope. */ -// NOTE: Remove markers after snapshot -#[cfg(stage1)] -#[cfg(stage2)] -#[cfg(stage3)] -pub use self::ascii::{Ascii, AsciiCast, OwnedAsciiCast, ToStrAscii}; - use at_vec; use cast; use char; @@ -40,13 +34,6 @@ use to_str::ToStr; #[cfg(notest)] use cmp::{Eq, Ord, Equiv, TotalEq}; -// NOTE: Remove markers after snapshot -#[cfg(stage1)] -#[cfg(stage2)] -#[cfg(stage3)] -#[path = "str/ascii.rs"] -mod ascii; - /* Section: Creating a string */ diff --git a/src/libcore/str/ascii.rs b/src/libcore/str/ascii.rs index 7de62a2c934..447ca3497e8 100644 --- a/src/libcore/str/ascii.rs +++ b/src/libcore/str/ascii.rs @@ -12,12 +12,8 @@ use to_str::{ToStr,ToStrConsume}; use str; use cast; -#[cfg(test)] -pub struct Ascii { priv chr: u8 } - /// Datatype to hold one ascii character. It is 8 bit long. -#[cfg(notest)] -#[deriving(Clone, Eq, Ord)] +#[deriving(Clone, Eq)] pub struct Ascii { priv chr: u8 } pub impl Ascii { @@ -163,18 +159,35 @@ impl OwnedAsciiCast for ~str { } /// Trait for converting an ascii type to a string. Needed to convert `&[Ascii]` to `~str` -pub trait ToStrAscii { +pub trait AsciiStr { /// Convert to a string. fn to_str_ascii(&self) -> ~str; + + /// Convert to vector representing a lower cased ascii string. + fn to_lower(&self) -> ~[Ascii]; + + /// Convert to vector representing a upper cased ascii string. + fn to_upper(&self) -> ~[Ascii]; + } -impl<'self> ToStrAscii for &'self [Ascii] { +impl<'self> AsciiStr for &'self [Ascii] { #[inline(always)] fn to_str_ascii(&self) -> ~str { let mut cpy = self.to_owned(); cpy.push(0u8.to_ascii()); unsafe {cast::transmute(cpy)} } + + #[inline(always)] + fn to_lower(&self) -> ~[Ascii] { + self.map(|a| a.to_lower()) + } + + #[inline(always)] + fn to_upper(&self) -> ~[Ascii] { + self.map(|a| a.to_upper()) + } } impl ToStrConsume for ~[Ascii] { @@ -186,13 +199,8 @@ impl ToStrConsume for ~[Ascii] { } } -// NOTE: Remove stage0 marker after snapshot -#[cfg(and(test, not(stage0)))] mod tests { use super::*; - use to_str::{ToStr,ToStrConsume}; - use str; - use cast; macro_rules! v2ascii ( ( [$($e:expr),*]) => ( [$(Ascii{chr:$e}),*]); @@ -206,15 +214,15 @@ mod tests { assert_eq!('A'.to_ascii().to_char(), 'A'); assert_eq!('A'.to_ascii().to_byte(), 65u8); - assert_eq!('A'.to_ascii().to_lower().to_char, 'a'); - assert_eq!('Z'.to_ascii().to_lower().to_char, 'z'); - assert_eq!('a'.to_ascii().to_upper().to_char, 'A'); - assert_eq!('z'.to_ascii().to_upper().to_char, 'Z'); + assert_eq!('A'.to_ascii().to_lower().to_char(), 'a'); + assert_eq!('Z'.to_ascii().to_lower().to_char(), 'z'); + assert_eq!('a'.to_ascii().to_upper().to_char(), 'A'); + assert_eq!('z'.to_ascii().to_upper().to_char(), 'Z'); - assert_eq!('@'.to_ascii().to_lower().to_char, '@'); - assert_eq!('['.to_ascii().to_lower().to_char, '['); - assert_eq!('`'.to_ascii().to_upper().to_char, '`'); - assert_eq!('{'.to_ascii().to_upper().to_char, '{'); + assert_eq!('@'.to_ascii().to_lower().to_char(), '@'); + assert_eq!('['.to_ascii().to_lower().to_char(), '['); + assert_eq!('`'.to_ascii().to_upper().to_char(), '`'); + assert_eq!('{'.to_ascii().to_upper().to_char(), '{'); } #[test] @@ -225,6 +233,9 @@ mod tests { // if chained-from directly let v = ~[40u8, 32u8, 59u8]; assert_eq!(v.to_ascii(), v2ascii!([40, 32, 59])); let v = ~"( ;"; assert_eq!(v.to_ascii(), v2ascii!([40, 32, 59])); + + assert_eq!("abCDef&?#".to_ascii().to_lower().to_str_ascii(), ~"abcdef&?#"); + assert_eq!("abCDef&?#".to_ascii().to_upper().to_str_ascii(), ~"ABCDEF&?#"); } #[test]