@@ -242,14 +242,18 @@ impl GenericPathUnsafe for Path {
242
242
fn is_vol_abs ( path : & str , prefix : Option < PathPrefix > ) -> bool {
243
243
// assume prefix is Some(DiskPrefix)
244
244
let rest = path. slice_from ( prefix_len ( prefix) ) ;
245
- !rest. is_empty ( ) && rest[ 0 ] . is_ascii ( ) && is_sep ( rest[ 0 ] as char )
245
+ !rest. is_empty ( ) && rest. as_bytes ( ) [ 0 ] . is_ascii ( ) && is_sep ( rest. as_bytes ( ) [ 0 ] as char )
246
246
}
247
247
fn shares_volume ( me : & Path , path : & str ) -> bool {
248
248
// path is assumed to have a prefix of Some(DiskPrefix)
249
249
let repr = me. repr . as_slice ( ) ;
250
250
match me. prefix {
251
- Some ( DiskPrefix ) => repr[ 0 ] == path[ 0 ] . to_ascii ( ) . to_upper ( ) . to_byte ( ) ,
252
- Some ( VerbatimDiskPrefix ) => repr[ 4 ] == path[ 0 ] . to_ascii ( ) . to_upper ( ) . to_byte ( ) ,
251
+ Some ( DiskPrefix ) => {
252
+ repr. as_bytes ( ) [ 0 ] == path. as_bytes ( ) [ 0 ] . to_ascii ( ) . to_upper ( ) . to_byte ( )
253
+ }
254
+ Some ( VerbatimDiskPrefix ) => {
255
+ repr. as_bytes ( ) [ 4 ] == path. as_bytes ( ) [ 0 ] . to_ascii ( ) . to_upper ( ) . to_byte ( )
256
+ }
253
257
_ => false
254
258
}
255
259
}
@@ -279,7 +283,7 @@ impl GenericPathUnsafe for Path {
279
283
// if me is "C:" we don't want to add a path separator
280
284
match me. prefix {
281
285
Some ( DiskPrefix ) if me. repr . len ( ) == plen => ( ) ,
282
- _ if !( me. repr . len ( ) > plen && me. repr . as_slice ( ) [ me. repr . len ( ) -1 ] == SEP_BYTE ) => {
286
+ _ if !( me. repr . len ( ) > plen && me. repr . as_bytes ( ) [ me. repr . len ( ) -1 ] == SEP_BYTE ) => {
283
287
s. push_char ( SEP ) ;
284
288
}
285
289
_ => ( )
@@ -302,7 +306,7 @@ impl GenericPathUnsafe for Path {
302
306
// absolute path, or cwd-relative and self is not same volume
303
307
replace_path ( self , path, prefix) ;
304
308
}
305
- None if !path. is_empty ( ) && is_sep_ ( self . prefix , path[ 0 ] ) => {
309
+ None if !path. is_empty ( ) && is_sep_ ( self . prefix , path. as_bytes ( ) [ 0 ] ) => {
306
310
// volume-relative path
307
311
if self . prefix . is_some ( ) {
308
312
// truncate self down to the prefix, then append
@@ -478,7 +482,7 @@ impl GenericPath for Path {
478
482
match self . prefix {
479
483
Some ( DiskPrefix ) => {
480
484
let rest = self . repr . as_slice ( ) . slice_from ( self . prefix_len ( ) ) ;
481
- rest. len ( ) > 0 && rest[ 0 ] == SEP_BYTE
485
+ rest. len ( ) > 0 && rest. as_bytes ( ) [ 0 ] == SEP_BYTE
482
486
}
483
487
Some ( _) => true ,
484
488
None => false
@@ -638,11 +642,11 @@ impl Path {
638
642
let s = match self . prefix {
639
643
Some ( _) => {
640
644
let plen = self . prefix_len ( ) ;
641
- if repr. len ( ) > plen && repr[ plen] == SEP_BYTE {
645
+ if repr. len ( ) > plen && repr. as_bytes ( ) [ plen] == SEP_BYTE {
642
646
repr. slice_from ( plen+1 )
643
647
} else { repr. slice_from ( plen) }
644
648
}
645
- None if repr[ 0 ] == SEP_BYTE => repr. slice_from ( 1 ) ,
649
+ None if repr. as_bytes ( ) [ 0 ] == SEP_BYTE => repr. slice_from ( 1 ) ,
646
650
None => repr
647
651
} ;
648
652
let ret = s. split_terminator ( SEP ) . map ( Some ) ;
@@ -665,14 +669,14 @@ impl Path {
665
669
match ( self . prefix , other. prefix ) {
666
670
( Some ( DiskPrefix ) , Some ( VerbatimDiskPrefix ) ) => {
667
671
self . is_absolute ( ) &&
668
- s_repr[ 0 ] . to_ascii ( ) . eq_ignore_case ( o_repr[ 4 ] . to_ascii ( ) )
672
+ s_repr. as_bytes ( ) [ 0 ] . to_ascii ( ) . eq_ignore_case ( o_repr. as_bytes ( ) [ 4 ] . to_ascii ( ) )
669
673
}
670
674
( Some ( VerbatimDiskPrefix ) , Some ( DiskPrefix ) ) => {
671
675
other. is_absolute ( ) &&
672
- s_repr[ 4 ] . to_ascii ( ) . eq_ignore_case ( o_repr[ 0 ] . to_ascii ( ) )
676
+ s_repr. as_bytes ( ) [ 4 ] . to_ascii ( ) . eq_ignore_case ( o_repr. as_bytes ( ) [ 0 ] . to_ascii ( ) )
673
677
}
674
678
( Some ( VerbatimDiskPrefix ) , Some ( VerbatimDiskPrefix ) ) => {
675
- s_repr[ 4 ] . to_ascii ( ) . eq_ignore_case ( o_repr[ 4 ] . to_ascii ( ) )
679
+ s_repr. as_bytes ( ) [ 4 ] . to_ascii ( ) . eq_ignore_case ( o_repr. as_bytes ( ) [ 4 ] . to_ascii ( ) )
676
680
}
677
681
( Some ( UNCPrefix ( _, _) ) , Some ( VerbatimUNCPrefix ( _, _) ) ) => {
678
682
s_repr. slice ( 2 , self . prefix_len ( ) ) == o_repr. slice ( 8 , other. prefix_len ( ) )
@@ -718,12 +722,12 @@ impl Path {
718
722
let mut comps = comps;
719
723
match ( comps. is_some ( ) , prefix) {
720
724
( false , Some ( DiskPrefix ) ) => {
721
- if s[ 0 ] >= 'a' as u8 && s[ 0 ] <= 'z' as u8 {
725
+ if s. as_bytes ( ) [ 0 ] >= 'a' as u8 && s. as_bytes ( ) [ 0 ] <= 'z' as u8 {
722
726
comps = Some ( vec ! [ ] ) ;
723
727
}
724
728
}
725
729
( false , Some ( VerbatimDiskPrefix ) ) => {
726
- if s[ 4 ] >= 'a' as u8 && s[ 0 ] <= 'z' as u8 {
730
+ if s. as_bytes ( ) [ 4 ] >= 'a' as u8 && s. as_bytes ( ) [ 0 ] <= 'z' as u8 {
727
731
comps = Some ( vec ! [ ] ) ;
728
732
}
729
733
}
@@ -778,12 +782,12 @@ impl Path {
778
782
let mut s = String :: with_capacity ( n) ;
779
783
match prefix {
780
784
Some ( DiskPrefix ) => {
781
- s. push_char ( prefix_[ 0 ] . to_ascii ( ) . to_upper ( ) . to_char ( ) ) ;
785
+ s. push_char ( prefix_. as_bytes ( ) [ 0 ] . to_ascii ( ) . to_upper ( ) . to_char ( ) ) ;
782
786
s. push_char ( ':' ) ;
783
787
}
784
788
Some ( VerbatimDiskPrefix ) => {
785
789
s. push_str ( prefix_. slice_to ( 4 ) ) ;
786
- s. push_char ( prefix_[ 4 ] . to_ascii ( ) . to_upper ( ) . to_char ( ) ) ;
790
+ s. push_char ( prefix_. as_bytes ( ) [ 4 ] . to_ascii ( ) . to_upper ( ) . to_char ( ) ) ;
787
791
s. push_str ( prefix_. slice_from ( 5 ) ) ;
788
792
}
789
793
Some ( UNCPrefix ( a, b) ) => {
@@ -845,7 +849,7 @@ impl Path {
845
849
846
850
fn has_nonsemantic_trailing_slash ( & self ) -> bool {
847
851
is_verbatim ( self ) && self . repr . len ( ) > self . prefix_len ( ) +1 &&
848
- self . repr . as_slice ( ) [ self . repr . len ( ) -1 ] == SEP_BYTE
852
+ self . repr . as_bytes ( ) [ self . repr . len ( ) -1 ] == SEP_BYTE
849
853
}
850
854
851
855
fn update_normalized < S : Str > ( & mut self , s : S ) {
@@ -861,7 +865,7 @@ impl Path {
861
865
/// but absolute within that volume.
862
866
#[ inline]
863
867
pub fn is_vol_relative ( path : & Path ) -> bool {
864
- path. prefix . is_none ( ) && is_sep_byte ( & path. repr . as_slice ( ) [ 0 ] )
868
+ path. prefix . is_none ( ) && is_sep_byte ( & path. repr . as_bytes ( ) [ 0 ] )
865
869
}
866
870
867
871
/// Returns whether the path is considered "cwd-relative", which means a path
@@ -991,8 +995,8 @@ fn parse_prefix<'a>(mut path: &'a str) -> Option<PathPrefix> {
991
995
} else {
992
996
// \\?\path
993
997
let idx = path. find ( '\\' ) ;
994
- if idx == Some ( 2 ) && path[ 1 ] == ':' as u8 {
995
- let c = path[ 0 ] ;
998
+ if idx == Some ( 2 ) && path. as_bytes ( ) [ 1 ] == ':' as u8 {
999
+ let c = path. as_bytes ( ) [ 0 ] ;
996
1000
if c. is_ascii ( ) && :: char:: is_alphabetic ( c as char ) {
997
1001
// \\?\C:\ path
998
1002
return Some ( VerbatimDiskPrefix ) ;
@@ -1014,9 +1018,9 @@ fn parse_prefix<'a>(mut path: &'a str) -> Option<PathPrefix> {
1014
1018
}
1015
1019
_ => ( )
1016
1020
}
1017
- } else if path. len ( ) > 1 && path[ 1 ] == ':' as u8 {
1021
+ } else if path. len ( ) > 1 && path. as_bytes ( ) [ 1 ] == ':' as u8 {
1018
1022
// C:
1019
- let c = path[ 0 ] ;
1023
+ let c = path. as_bytes ( ) [ 0 ] ;
1020
1024
if c. is_ascii ( ) && :: char:: is_alphabetic ( c as char ) {
1021
1025
return Some ( DiskPrefix ) ;
1022
1026
}
0 commit comments