Skip to content

Commit 582a05f

Browse files
committed
Moved ascii out of str
Removed deriving Ord, which allowed to remove the stage markers
1 parent df61ec2 commit 582a05f

File tree

4 files changed

+35
-38
lines changed

4 files changed

+35
-38
lines changed

src/libcore/core.rc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ pub mod vec;
159159
pub mod at_vec;
160160
pub mod str;
161161

162+
#[path = "str/ascii.rs"]
163+
pub mod ascii;
164+
162165
pub mod ptr;
163166
pub mod owned;
164167
pub mod managed;

src/libcore/prelude.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ pub use path::Path;
4040
pub use path::PosixPath;
4141
pub use path::WindowsPath;
4242
pub use ptr::Ptr;
43-
// NOTE: Remove markers after snapshot
44-
#[cfg(stage1)]
45-
#[cfg(stage2)]
46-
#[cfg(stage3)]
47-
pub use str::{Ascii, AsciiCast, OwnedAsciiCast, ToStrAscii};
43+
pub use ascii::{Ascii, AsciiCast, OwnedAsciiCast, AsciiStr};
4844
pub use str::{StrSlice, OwnedStr};
4945
pub use to_bytes::IterBytes;
5046
pub use to_str::{ToStr, ToStrConsume};

src/libcore/str.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717
* some heavy-duty uses, try std::rope.
1818
*/
1919

20-
// NOTE: Remove markers after snapshot
21-
#[cfg(stage1)]
22-
#[cfg(stage2)]
23-
#[cfg(stage3)]
24-
pub use self::ascii::{Ascii, AsciiCast, OwnedAsciiCast, ToStrAscii};
25-
2620
use at_vec;
2721
use cast;
2822
use char;
@@ -40,13 +34,6 @@ use to_str::ToStr;
4034

4135
#[cfg(notest)] use cmp::{Eq, Ord, Equiv, TotalEq};
4236

43-
// NOTE: Remove markers after snapshot
44-
#[cfg(stage1)]
45-
#[cfg(stage2)]
46-
#[cfg(stage3)]
47-
#[path = "str/ascii.rs"]
48-
mod ascii;
49-
5037
/*
5138
Section: Creating a string
5239
*/

src/libcore/str/ascii.rs

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ use to_str::{ToStr,ToStrConsume};
1212
use str;
1313
use cast;
1414

15-
#[cfg(test)]
16-
pub struct Ascii { priv chr: u8 }
17-
1815
/// Datatype to hold one ascii character. It is 8 bit long.
19-
#[cfg(notest)]
20-
#[deriving(Clone, Eq, Ord)]
16+
#[deriving(Clone, Eq)]
2117
pub struct Ascii { priv chr: u8 }
2218

2319
pub impl Ascii {
@@ -163,18 +159,35 @@ impl OwnedAsciiCast for ~str {
163159
}
164160

165161
/// Trait for converting an ascii type to a string. Needed to convert `&[Ascii]` to `~str`
166-
pub trait ToStrAscii {
162+
pub trait AsciiStr {
167163
/// Convert to a string.
168164
fn to_str_ascii(&self) -> ~str;
165+
166+
/// Convert to vector representing a lower cased ascii string.
167+
fn to_lower(&self) -> ~[Ascii];
168+
169+
/// Convert to vector representing a upper cased ascii string.
170+
fn to_upper(&self) -> ~[Ascii];
171+
169172
}
170173

171-
impl<'self> ToStrAscii for &'self [Ascii] {
174+
impl<'self> AsciiStr for &'self [Ascii] {
172175
#[inline(always)]
173176
fn to_str_ascii(&self) -> ~str {
174177
let mut cpy = self.to_owned();
175178
cpy.push(0u8.to_ascii());
176179
unsafe {cast::transmute(cpy)}
177180
}
181+
182+
#[inline(always)]
183+
fn to_lower(&self) -> ~[Ascii] {
184+
self.map(|a| a.to_lower())
185+
}
186+
187+
#[inline(always)]
188+
fn to_upper(&self) -> ~[Ascii] {
189+
self.map(|a| a.to_upper())
190+
}
178191
}
179192

180193
impl ToStrConsume for ~[Ascii] {
@@ -186,13 +199,8 @@ impl ToStrConsume for ~[Ascii] {
186199
}
187200
}
188201

189-
// NOTE: Remove stage0 marker after snapshot
190-
#[cfg(and(test, not(stage0)))]
191202
mod tests {
192203
use super::*;
193-
use to_str::{ToStr,ToStrConsume};
194-
use str;
195-
use cast;
196204

197205
macro_rules! v2ascii (
198206
( [$($e:expr),*]) => ( [$(Ascii{chr:$e}),*]);
@@ -206,15 +214,15 @@ mod tests {
206214
assert_eq!('A'.to_ascii().to_char(), 'A');
207215
assert_eq!('A'.to_ascii().to_byte(), 65u8);
208216

209-
assert_eq!('A'.to_ascii().to_lower().to_char, 'a');
210-
assert_eq!('Z'.to_ascii().to_lower().to_char, 'z');
211-
assert_eq!('a'.to_ascii().to_upper().to_char, 'A');
212-
assert_eq!('z'.to_ascii().to_upper().to_char, 'Z');
217+
assert_eq!('A'.to_ascii().to_lower().to_char(), 'a');
218+
assert_eq!('Z'.to_ascii().to_lower().to_char(), 'z');
219+
assert_eq!('a'.to_ascii().to_upper().to_char(), 'A');
220+
assert_eq!('z'.to_ascii().to_upper().to_char(), 'Z');
213221

214-
assert_eq!('@'.to_ascii().to_lower().to_char, '@');
215-
assert_eq!('['.to_ascii().to_lower().to_char, '[');
216-
assert_eq!('`'.to_ascii().to_upper().to_char, '`');
217-
assert_eq!('{'.to_ascii().to_upper().to_char, '{');
222+
assert_eq!('@'.to_ascii().to_lower().to_char(), '@');
223+
assert_eq!('['.to_ascii().to_lower().to_char(), '[');
224+
assert_eq!('`'.to_ascii().to_upper().to_char(), '`');
225+
assert_eq!('{'.to_ascii().to_upper().to_char(), '{');
218226
}
219227

220228
#[test]
@@ -225,6 +233,9 @@ mod tests {
225233
// if chained-from directly
226234
let v = ~[40u8, 32u8, 59u8]; assert_eq!(v.to_ascii(), v2ascii!([40, 32, 59]));
227235
let v = ~"( ;"; assert_eq!(v.to_ascii(), v2ascii!([40, 32, 59]));
236+
237+
assert_eq!("abCDef&?#".to_ascii().to_lower().to_str_ascii(), ~"abcdef&?#");
238+
assert_eq!("abCDef&?#".to_ascii().to_upper().to_str_ascii(), ~"ABCDEF&?#");
228239
}
229240
230241
#[test]

0 commit comments

Comments
 (0)