Skip to content

Commit 9207840

Browse files
Kroissealexcrichton
authored andcommitted
---
yaml --- r: 105451 b: refs/heads/master c: e627bce h: refs/heads/master i: 105449: b88435d 105447: a5d4e4a v: v3
1 parent 573c314 commit 9207840

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 22655120332293901f8d4cb822e10a8aa6ee3697
2+
refs/heads/master: e627bce939cfe83b9c8b02c5805388b472d3dfcf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: b8601a3d8b91ad3b653d143307611f2f5c75617e
55
refs/heads/try: db814977d07bd798feb24f6b74c00800ef458a13

trunk/src/libstd/ascii.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use cast;
2020
use fmt;
2121
use iter::Iterator;
2222
use vec::{ImmutableVector, MutableVector, Vector};
23+
use vec_ng::Vec;
2324
use option::{Option, Some, None};
2425

2526
/// Datatype to hold one ascii character. It wraps a `u8`, with the highest bit always zero.
@@ -305,6 +306,14 @@ impl IntoStr for ~[Ascii] {
305306
}
306307
}
307308

309+
impl IntoStr for Vec<Ascii> {
310+
#[inline]
311+
fn into_str(self) -> ~str {
312+
let v: ~[Ascii] = self.move_iter().collect();
313+
unsafe { cast::transmute(v) }
314+
}
315+
}
316+
308317
/// Trait to convert to an owned byte array by consuming self
309318
pub trait IntoBytes {
310319
/// Converts to an owned byte array by consuming self
@@ -473,13 +482,18 @@ mod tests {
473482
use super::*;
474483
use str::from_char;
475484
use char::from_u32;
485+
use vec_ng::Vec;
476486

477487
macro_rules! v2ascii (
478488
( [$($e:expr),*]) => (&[$(Ascii{chr:$e}),*]);
479489
(&[$($e:expr),*]) => (&[$(Ascii{chr:$e}),*]);
480490
(~[$($e:expr),*]) => (~[$(Ascii{chr:$e}),*]);
481491
)
482492

493+
macro_rules! vec2ascii (
494+
($($e:expr),*) => (Vec::from_slice([$(Ascii{chr:$e}),*]));
495+
)
496+
483497
#[test]
484498
fn test_ascii() {
485499
assert_eq!(65u8.to_ascii().to_byte(), 65u8);
@@ -535,6 +549,17 @@ mod tests {
535549

536550
}
537551

552+
#[test]
553+
fn test_ascii_vec_ng() {
554+
assert_eq!(Vec::from_slice("abCDef&?#".to_ascii().to_lower()).into_str(), ~"abcdef&?#");
555+
assert_eq!(Vec::from_slice("abCDef&?#".to_ascii().to_upper()).into_str(), ~"ABCDEF&?#");
556+
557+
assert_eq!(Vec::from_slice("".to_ascii().to_lower()).into_str(), ~"");
558+
assert_eq!(Vec::from_slice("YMCA".to_ascii().to_lower()).into_str(), ~"ymca");
559+
assert_eq!(Vec::from_slice("abcDEFxyz:.;".to_ascii().to_upper()).into_str(),
560+
~"ABCDEFXYZ:.;");
561+
}
562+
538563
#[test]
539564
fn test_owned_ascii_vec() {
540565
assert_eq!((~"( ;").into_ascii(), v2ascii!(~[40, 32, 59]));
@@ -550,6 +575,7 @@ mod tests {
550575
#[test]
551576
fn test_ascii_into_str() {
552577
assert_eq!(v2ascii!(~[40, 32, 59]).into_str(), ~"( ;");
578+
assert_eq!(vec2ascii!(40, 32, 59).into_str(), ~"( ;");
553579
}
554580
555581
#[test]

0 commit comments

Comments
 (0)