@@ -17,7 +17,7 @@ use str::OwnedStr;
17
17
use container:: Container ;
18
18
use cast;
19
19
use iter:: Iterator ;
20
- use vec:: { CopyableVector , ImmutableVector , MutableVector } ;
20
+ use vec:: { ImmutableVector , MutableVector } ;
21
21
use to_bytes:: IterBytes ;
22
22
use option:: { Some , None } ;
23
23
@@ -154,10 +154,10 @@ impl AsciiCast<Ascii> for char {
154
154
155
155
/// Trait for copyless casting to an ascii vector.
156
156
pub trait OwnedAsciiCast {
157
- /// Take ownership and cast to an ascii vector without trailing zero element .
157
+ /// Take ownership and cast to an ascii vector.
158
158
fn into_ascii ( self ) -> ~[ Ascii ] ;
159
159
160
- /// Take ownership and cast to an ascii vector without trailing zero element .
160
+ /// Take ownership and cast to an ascii vector.
161
161
/// Does not perform validation checks.
162
162
unsafe fn into_ascii_nocheck ( self ) -> ~[ Ascii ] ;
163
163
}
@@ -188,26 +188,26 @@ impl OwnedAsciiCast for ~str {
188
188
}
189
189
}
190
190
191
- /// Trait for converting an ascii type to a string. Needed to convert `&[Ascii]` to `~str`
191
+ /// Trait for converting an ascii type to a string. Needed to convert
192
+ /// `&[Ascii]` to `&str`.
192
193
pub trait AsciiStr {
193
194
/// Convert to a string.
194
- fn to_str_ascii ( & self ) -> ~ str ;
195
+ fn as_str_ascii < ' a > ( & ' a self ) -> & ' a str ;
195
196
196
197
/// Convert to vector representing a lower cased ascii string.
197
198
fn to_lower ( & self ) -> ~[ Ascii ] ;
198
199
199
200
/// Convert to vector representing a upper cased ascii string.
200
201
fn to_upper ( & self ) -> ~[ Ascii ] ;
201
202
202
- /// Compares two Ascii strings ignoring case
203
+ /// Compares two Ascii strings ignoring case.
203
204
fn eq_ignore_case ( self , other : & [ Ascii ] ) -> bool ;
204
205
}
205
206
206
207
impl < ' self > AsciiStr for & ' self [ Ascii ] {
207
208
#[ inline]
208
- fn to_str_ascii ( & self ) -> ~str {
209
- let cpy = self . to_owned ( ) ;
210
- unsafe { cast:: transmute ( cpy) }
209
+ fn as_str_ascii < ' a > ( & ' a self ) -> & ' a str {
210
+ unsafe { cast:: transmute ( * self ) }
211
211
}
212
212
213
213
#[ inline]
@@ -443,12 +443,12 @@ mod tests {
443
443
let v = ~[ 40u8 , 32u8 , 59u8 ] ; assert_eq ! ( v. to_ascii( ) , v2ascii!( [ 40 , 32 , 59 ] ) ) ;
444
444
let v = ~"( ; "; assert_eq!(v.to_ascii(), v2ascii!([40, 32, 59]));
445
445
446
- assert_eq!(" abCDef& ?#". to_ascii ( ) . to_lower ( ) . to_str_ascii ( ) , ~"abcdef& ?#") ;
447
- assert_eq ! ( "abCDef&?#" . to_ascii( ) . to_upper( ) . to_str_ascii ( ) , ~"ABCDEF & ?#");
446
+ assert_eq!(" abCDef& ?#". to_ascii ( ) . to_lower ( ) . into_str ( ) , ~"abcdef& ?#") ;
447
+ assert_eq ! ( "abCDef&?#" . to_ascii( ) . to_upper( ) . into_str ( ) , ~"ABCDEF & ?#");
448
448
449
- assert_eq!(" ".to_ascii().to_lower().to_str_ascii (), ~" ");
450
- assert_eq!(" YMCA ".to_ascii().to_lower().to_str_ascii (), ~" ymca");
451
- assert_eq!(" abcDEFxyz: . ; ".to_ascii().to_upper().to_str_ascii (), ~" ABCDEFXYZ : . ; ");
449
+ assert_eq!(" ".to_ascii().to_lower().into_str (), ~" ");
450
+ assert_eq!(" YMCA ".to_ascii().to_lower().into_str (), ~" ymca");
451
+ assert_eq!(" abcDEFxyz: . ; ".to_ascii().to_upper().into_str (), ~" ABCDEFXYZ : . ; ");
452
452
453
453
assert!(" aBcDeF& ?#".to_ascii().eq_ignore_case(" AbCdEf & ?#".to_ascii()));
454
454
@@ -465,7 +465,10 @@ mod tests {
465
465
}
466
466
467
467
#[test]
468
- fn test_ascii_to_str() { assert_eq!(v2ascii!([40, 32, 59]).to_str_ascii(), ~" ( ; "); }
468
+ fn test_ascii_as_str() {
469
+ let v = v2ascii!([40, 32, 59]);
470
+ assert_eq!(v.as_str_ascii(), " ( ; ");
471
+ }
469
472
470
473
#[test]
471
474
fn test_ascii_into_str() {
0 commit comments