Skip to content

Commit bc3b26e

Browse files
Kroissealexcrichton
authored andcommitted
---
yaml --- r: 150069 b: refs/heads/try2 c: e627bce h: refs/heads/master i: 150067: c44c3fc v: v3
1 parent 80d1608 commit bc3b26e

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 22655120332293901f8d4cb822e10a8aa6ee3697
8+
refs/heads/try2: e627bce939cfe83b9c8b02c5805388b472d3dfcf
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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)