@@ -20,6 +20,7 @@ use cast;
2020use fmt;
2121use iter:: Iterator ;
2222use vec:: { ImmutableVector , MutableVector , Vector } ;
23+ use vec_ng:: Vec ;
2324use 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
309318pub 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