@@ -54,7 +54,7 @@ impl Copy for CodePoint {}
54
54
55
55
/// Format the code point as `U+` followed by four to six hexadecimal digits.
56
56
/// Example: `U+1F4A9`
57
- impl fmt:: Show for CodePoint {
57
+ impl fmt:: Debug for CodePoint {
58
58
#[ inline]
59
59
fn fmt ( & self , formatter : & mut fmt:: Formatter ) -> Result < ( ) , fmt:: Error > {
60
60
write ! ( formatter, "U+{:04X}" , self . value)
@@ -138,7 +138,7 @@ impl Deref for Wtf8Buf {
138
138
/// Format the string with double quotes,
139
139
/// and surrogates as `\u` followed by four hexadecimal digits.
140
140
/// Example: `"a\u{D800}"` for a string with code points [U+0061, U+D800]
141
- impl fmt:: Show for Wtf8Buf {
141
+ impl fmt:: Debug for Wtf8Buf {
142
142
#[ inline]
143
143
fn fmt ( & self , formatter : & mut fmt:: Formatter ) -> Result < ( ) , fmt:: Error > {
144
144
self . as_slice ( ) . fmt ( formatter)
@@ -257,7 +257,7 @@ impl Wtf8Buf {
257
257
( Some ( lead) , Some ( trail) ) => {
258
258
let len_without_lead_surrogate = self . len ( ) - 3 ;
259
259
self . bytes . truncate ( len_without_lead_surrogate) ;
260
- let other_without_trail_surrogate = other. bytes . slice_from ( 3 ) ;
260
+ let other_without_trail_surrogate = & other. bytes [ 3 .. ] ;
261
261
// 4 bytes for the supplementary code point
262
262
self . bytes . reserve ( 4 + other_without_trail_surrogate. len ( ) ) ;
263
263
self . push_char ( decode_surrogate_pair ( lead, trail) ) ;
@@ -337,7 +337,7 @@ impl Wtf8Buf {
337
337
Some ( ( surrogate_pos, _) ) => {
338
338
pos = surrogate_pos + 3 ;
339
339
slice:: bytes:: copy_memory (
340
- self . bytes . slice_mut ( surrogate_pos, pos) ,
340
+ & mut self . bytes [ surrogate_pos.. pos] ,
341
341
UTF8_REPLACEMENT_CHARACTER
342
342
) ;
343
343
} ,
@@ -418,7 +418,7 @@ impl Ord for Wtf8 {
418
418
/// Format the slice with double quotes,
419
419
/// and surrogates as `\u` followed by four hexadecimal digits.
420
420
/// Example: `"a\u{D800}"` for a slice with code points [U+0061, U+D800]
421
- impl fmt:: Show for Wtf8 {
421
+ impl fmt:: Debug for Wtf8 {
422
422
fn fmt ( & self , formatter : & mut fmt:: Formatter ) -> Result < ( ) , fmt:: Error > {
423
423
try!( formatter. write_str ( "\" " ) ) ;
424
424
let mut pos = 0 ;
@@ -427,15 +427,15 @@ impl fmt::Show for Wtf8 {
427
427
None => break ,
428
428
Some ( ( surrogate_pos, surrogate) ) => {
429
429
try!( formatter. write_str ( unsafe {
430
- str:: from_utf8_unchecked ( self . bytes . slice ( pos, surrogate_pos) )
430
+ str:: from_utf8_unchecked ( & self . bytes [ pos.. surrogate_pos] )
431
431
} ) ) ;
432
432
try!( write ! ( formatter, "\\ u{{{:X}}}" , surrogate) ) ;
433
433
pos = surrogate_pos + 3 ;
434
434
}
435
435
}
436
436
}
437
437
try!( formatter. write_str ( unsafe {
438
- str:: from_utf8_unchecked ( self . bytes . slice_from ( pos) )
438
+ str:: from_utf8_unchecked ( & self . bytes [ pos.. ] )
439
439
} ) ) ;
440
440
formatter. write_str ( "\" " )
441
441
}
@@ -579,18 +579,18 @@ impl Wtf8 {
579
579
} ;
580
580
let wtf8_bytes = & self . bytes ;
581
581
let mut utf8_bytes = Vec :: with_capacity ( self . len ( ) ) ;
582
- utf8_bytes. push_all ( wtf8_bytes. slice_to ( surrogate_pos) ) ;
582
+ utf8_bytes. push_all ( & wtf8_bytes[ .. surrogate_pos] ) ;
583
583
utf8_bytes. push_all ( UTF8_REPLACEMENT_CHARACTER ) ;
584
584
let mut pos = surrogate_pos + 3 ;
585
585
loop {
586
586
match self . next_surrogate ( pos) {
587
587
Some ( ( surrogate_pos, _) ) => {
588
- utf8_bytes. push_all ( wtf8_bytes. slice ( pos, surrogate_pos) ) ;
588
+ utf8_bytes. push_all ( & wtf8_bytes[ pos.. surrogate_pos] ) ;
589
589
utf8_bytes. push_all ( UTF8_REPLACEMENT_CHARACTER ) ;
590
590
pos = surrogate_pos + 3 ;
591
591
} ,
592
592
None => {
593
- utf8_bytes. push_all ( wtf8_bytes. slice_from ( pos) ) ;
593
+ utf8_bytes. push_all ( & wtf8_bytes[ pos.. ] ) ;
594
594
return Cow :: Owned ( unsafe { String :: from_utf8_unchecked ( utf8_bytes) } )
595
595
}
596
596
}
@@ -610,7 +610,7 @@ impl Wtf8 {
610
610
611
611
#[ inline]
612
612
fn next_surrogate ( & self , mut pos : usize ) -> Option < ( usize , u16 ) > {
613
- let mut iter = self . bytes . slice_from ( pos) . iter ( ) ;
613
+ let mut iter = self . bytes [ pos.. ] . iter ( ) ;
614
614
loop {
615
615
let b = match iter. next ( ) {
616
616
None => return None ,
@@ -647,7 +647,7 @@ impl Wtf8 {
647
647
if len < 3 {
648
648
return None
649
649
}
650
- match self . bytes . slice_from ( len - 3 ) {
650
+ match & self . bytes [ len - 3 .. ] {
651
651
[ 0xED , b2 @ 0xA0 ...0xAF , b3] => Some ( decode_surrogate ( b2, b3) ) ,
652
652
_ => None
653
653
}
@@ -659,7 +659,7 @@ impl Wtf8 {
659
659
if len < 3 {
660
660
return None
661
661
}
662
- match self . bytes . slice_to ( 3 ) {
662
+ match & self . bytes [ .. 3 ] {
663
663
[ 0xED , b2 @ 0xB0 ...0xBF , b3] => Some ( decode_surrogate ( b2, b3) ) ,
664
664
_ => None
665
665
}
@@ -768,6 +768,7 @@ impl<'a, S: hash::Hasher + hash::Writer> Hash<S> for Wtf8 {
768
768
#[ cfg( test) ]
769
769
mod tests {
770
770
use std:: borrow:: Cow ;
771
+ use std:: string:: CowString ;
771
772
use std:: mem:: transmute;
772
773
use super :: * ;
773
774
@@ -1021,7 +1022,7 @@ mod tests {
1021
1022
}
1022
1023
1023
1024
#[ test]
1024
- fn wtf8buf_show ( ) {
1025
+ fn wtf8buf_debug ( ) {
1025
1026
let mut string = Wtf8Buf :: from_str ( "aé 💩" ) ;
1026
1027
string. push ( CodePoint :: from_u32 ( 0xD800 ) . unwrap ( ) ) ;
1027
1028
assert_eq ! ( format!( "{:?}" , string) , r#""aé 💩\u{D800}""# ) ;
@@ -1033,7 +1034,7 @@ mod tests {
1033
1034
}
1034
1035
1035
1036
#[ test]
1036
- fn wtf8_show ( ) {
1037
+ fn wtf8_debug ( ) {
1037
1038
let mut string = Wtf8Buf :: from_str ( "aé 💩" ) ;
1038
1039
string. push ( CodePoint :: from_u32 ( 0xD800 ) . unwrap ( ) ) ;
1039
1040
assert_eq ! ( format!( "{:?}" , string. as_slice( ) ) , r#""aé 💩\u{D800}""# ) ;
@@ -1147,7 +1148,10 @@ mod tests {
1147
1148
assert_eq ! ( Wtf8 :: from_str( "aé 💩" ) . to_string_lossy( ) , Cow :: Borrowed ( "aé 💩" ) ) ;
1148
1149
let mut string = Wtf8Buf :: from_str ( "aé 💩" ) ;
1149
1150
string. push ( CodePoint :: from_u32 ( 0xD800 ) . unwrap ( ) ) ;
1150
- assert_eq ! ( string. to_string_lossy( ) , Cow :: Owned ( String :: from_str( "aé 💩�" ) ) ) ;
1151
+ assert_eq ! ( string. to_string_lossy( ) , {
1152
+ let o: CowString = Cow :: Owned ( String :: from_str( "aé 💩�" ) ) ;
1153
+ o
1154
+ } ) ;
1151
1155
}
1152
1156
1153
1157
#[ test]
0 commit comments