@@ -20,6 +20,7 @@ use cast;
20
20
use fmt;
21
21
use iter:: Iterator ;
22
22
use vec:: { ImmutableVector , MutableVector , Vector } ;
23
+ use vec_ng:: Vec ;
23
24
use option:: { Option , Some , None } ;
24
25
25
26
/// Datatype to hold one ascii character. It wraps a `u8`, with the highest bit always zero.
@@ -305,6 +306,14 @@ impl IntoStr for ~[Ascii] {
305
306
}
306
307
}
307
308
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
+
308
317
/// Trait to convert to an owned byte array by consuming self
309
318
pub trait IntoBytes {
310
319
/// Converts to an owned byte array by consuming self
@@ -473,13 +482,18 @@ mod tests {
473
482
use super :: * ;
474
483
use str:: from_char;
475
484
use char:: from_u32;
485
+ use vec_ng:: Vec ;
476
486
477
487
macro_rules! v2ascii (
478
488
( [ $( $e: expr) ,* ] ) => ( & [ $( Ascii { chr: $e} ) ,* ] ) ;
479
489
( & [ $( $e: expr) ,* ] ) => ( & [ $( Ascii { chr: $e} ) ,* ] ) ;
480
490
( ~[ $( $e: expr) ,* ] ) => ( ~[ $( Ascii { chr: $e} ) ,* ] ) ;
481
491
)
482
492
493
+ macro_rules! vec2ascii (
494
+ ( $( $e: expr) ,* ) => ( Vec :: from_slice( [ $( Ascii { chr: $e} ) ,* ] ) ) ;
495
+ )
496
+
483
497
#[ test]
484
498
fn test_ascii ( ) {
485
499
assert_eq ! ( 65u8 . to_ascii( ) . to_byte( ) , 65u8 ) ;
@@ -535,6 +549,17 @@ mod tests {
535
549
536
550
}
537
551
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
+
538
563
#[test]
539
564
fn test_owned_ascii_vec() {
540
565
assert_eq!((~" ( ; ").into_ascii(), v2ascii!(~[40, 32, 59]));
@@ -550,6 +575,7 @@ mod tests {
550
575
#[test]
551
576
fn test_ascii_into_str() {
552
577
assert_eq!(v2ascii!(~[40, 32, 59]).into_str(), ~" ( ; ");
578
+ assert_eq!(vec2ascii!(40, 32, 59).into_str(), ~" ( ; ");
553
579
}
554
580
555
581
#[test]
0 commit comments