Skip to content

Commit 81a2cb3

Browse files
Kroissealexcrichton
authored andcommitted
---
yaml --- r: 106069 b: refs/heads/auto c: e627bce h: refs/heads/master i: 106067: 63b7401 v: v3
1 parent e0850a3 commit 81a2cb3

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
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 22655120332293901f8d4cb822e10a8aa6ee3697
16+
refs/heads/auto: e627bce939cfe83b9c8b02c5805388b472d3dfcf
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

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