@@ -183,7 +183,7 @@ impl GenericPathUnsafe for Path {
183
183
None if ".." == self . repr => {
184
184
let mut s = str:: with_capacity ( 3 + filename. len ( ) ) ;
185
185
s. push_str ( ".." ) ;
186
- s. push_char ( sep ) ;
186
+ s. push_char ( SEP ) ;
187
187
s. push_str ( filename) ;
188
188
self . update_normalized ( s) ;
189
189
}
@@ -193,7 +193,7 @@ impl GenericPathUnsafe for Path {
193
193
Some ( ( _, idxa, end) ) if self . repr . slice ( idxa, end) == ".." => {
194
194
let mut s = str:: with_capacity ( end + 1 + filename. len ( ) ) ;
195
195
s. push_str ( self . repr . slice_to ( end) ) ;
196
- s. push_char ( sep ) ;
196
+ s. push_char ( SEP ) ;
197
197
s. push_str ( filename) ;
198
198
self . update_normalized ( s) ;
199
199
}
@@ -206,7 +206,7 @@ impl GenericPathUnsafe for Path {
206
206
Some ( ( idxb, _, _) ) => {
207
207
let mut s = str:: with_capacity ( idxb + 1 + filename. len ( ) ) ;
208
208
s. push_str ( self . repr . slice_to ( idxb) ) ;
209
- s. push_char ( sep ) ;
209
+ s. push_char ( SEP ) ;
210
210
s. push_str ( filename) ;
211
211
self . update_normalized ( s) ;
212
212
}
@@ -264,8 +264,8 @@ impl GenericPathUnsafe for Path {
264
264
// if me is "C:" we don't want to add a path separator
265
265
match me. prefix {
266
266
Some ( DiskPrefix ) if me. repr . len ( ) == plen => ( ) ,
267
- _ if !( me. repr . len ( ) > plen && me. repr [ me. repr . len ( ) -1 ] == sep as u8 ) => {
268
- s. push_char ( sep ) ;
267
+ _ if !( me. repr . len ( ) > plen && me. repr [ me. repr . len ( ) -1 ] == SEP_BYTE ) => {
268
+ s. push_char ( SEP ) ;
269
269
}
270
270
_ => ( )
271
271
}
@@ -460,7 +460,7 @@ impl GenericPath for Path {
460
460
match self . prefix {
461
461
Some ( DiskPrefix ) => {
462
462
let rest = self . repr . slice_from ( self . prefix_len ( ) ) ;
463
- rest. len ( ) > 0 && rest[ 0 ] == sep as u8
463
+ rest. len ( ) > 0 && rest[ 0 ] == SEP_BYTE
464
464
}
465
465
Some ( _) => true ,
466
466
None => false
@@ -501,7 +501,7 @@ impl GenericPath for Path {
501
501
502
502
fn path_relative_from ( & self , base : & Path ) -> Option < Path > {
503
503
fn comp_requires_verbatim ( s : & str ) -> bool {
504
- s == "." || s == ".." || s. contains_char ( sep2 )
504
+ s == "." || s == ".." || s. contains_char ( SEP2 )
505
505
}
506
506
507
507
if !self . equiv_prefix ( base) {
@@ -619,14 +619,14 @@ impl Path {
619
619
let s = match self . prefix {
620
620
Some ( _) => {
621
621
let plen = self . prefix_len ( ) ;
622
- if self . repr . len ( ) > plen && self . repr [ plen] == sep as u8 {
622
+ if self . repr . len ( ) > plen && self . repr [ plen] == SEP_BYTE {
623
623
self . repr . slice_from ( plen+1 )
624
624
} else { self . repr . slice_from ( plen) }
625
625
}
626
- None if self . repr [ 0 ] == sep as u8 => self . repr . slice_from ( 1 ) ,
626
+ None if self . repr [ 0 ] == SEP_BYTE => self . repr . slice_from ( 1 ) ,
627
627
None => self . repr . as_slice ( )
628
628
} ;
629
- let ret = s. split_terminator ( sep ) . map ( Some ) ;
629
+ let ret = s. split_terminator ( SEP ) . map ( Some ) ;
630
630
ret
631
631
}
632
632
@@ -703,7 +703,7 @@ impl Path {
703
703
Some ( VerbatimUNCPrefix ( x, 0 ) ) if s. len ( ) == 8 + x => {
704
704
// the server component has no trailing '\'
705
705
let mut s = s. into_owned ( ) ;
706
- s. push_char ( sep ) ;
706
+ s. push_char ( SEP ) ;
707
707
Some ( s)
708
708
}
709
709
_ => None
@@ -739,7 +739,7 @@ impl Path {
739
739
if is_abs {
740
740
// normalize C:/ to C:\
741
741
unsafe {
742
- str:: raw:: as_owned_vec ( & mut s) [ 2 ] = sep as u8 ;
742
+ str:: raw:: as_owned_vec ( & mut s) [ 2 ] = SEP_BYTE ;
743
743
}
744
744
}
745
745
Some ( s)
@@ -761,7 +761,7 @@ impl Path {
761
761
}
762
762
}
763
763
} else if is_abs && comps. is_empty ( ) {
764
- Some ( str:: from_char ( sep ) )
764
+ Some ( str:: from_char ( SEP ) )
765
765
} else {
766
766
let prefix_ = s. slice_to ( prefix_len ( prefix) ) ;
767
767
let n = prefix_. len ( ) +
@@ -781,7 +781,7 @@ impl Path {
781
781
Some ( UNCPrefix ( a, b) ) => {
782
782
s. push_str ( "\\ \\ " ) ;
783
783
s. push_str ( prefix_. slice ( 2 , a+2 ) ) ;
784
- s. push_char ( sep ) ;
784
+ s. push_char ( SEP ) ;
785
785
s. push_str ( prefix_. slice ( 3 +a, 3 +a+b) ) ;
786
786
}
787
787
Some ( _) => s. push_str ( prefix_) ,
@@ -795,7 +795,7 @@ impl Path {
795
795
}
796
796
}
797
797
for comp in it {
798
- s. push_char ( sep ) ;
798
+ s. push_char ( SEP ) ;
799
799
s. push_str ( comp) ;
800
800
}
801
801
Some ( s)
@@ -837,7 +837,7 @@ impl Path {
837
837
838
838
fn has_nonsemantic_trailing_slash ( & self ) -> bool {
839
839
is_verbatim ( self ) && self . repr . len ( ) > self . prefix_len ( ) +1 &&
840
- self . repr [ self . repr . len ( ) -1 ] == sep as u8
840
+ self . repr [ self . repr . len ( ) -1 ] == SEP_BYTE
841
841
}
842
842
843
843
fn update_normalized < S : Str > ( & mut self , s : S ) {
@@ -877,36 +877,41 @@ pub fn is_verbatim(path: &Path) -> bool {
877
877
}
878
878
879
879
/// The standard path separator character
880
- pub static sep: char = '\\' ;
880
+ pub static SEP : char = '\\' ;
881
+ /// The standard path separator byte
882
+ pub static SEP_BYTE : u8 = SEP as u8 ;
883
+
884
+ /// The alternative path separator character
885
+ pub static SEP2 : char = '/' ;
881
886
/// The alternative path separator character
882
- pub static sep2 : char = '/' ;
887
+ pub static SEP2_BYTE : u8 = SEP2 as u8 ;
883
888
884
889
/// Returns whether the given char is a path separator.
885
890
/// Allows both the primary separator '\' and the alternative separator '/'.
886
891
#[ inline]
887
892
pub fn is_sep ( c : char ) -> bool {
888
- c == sep || c == sep2
893
+ c == SEP || c == SEP2
889
894
}
890
895
891
896
/// Returns whether the given char is a path separator.
892
897
/// Only allows the primary separator '\'; use is_sep to allow '/'.
893
898
#[ inline]
894
899
pub fn is_sep_verbatim ( c : char ) -> bool {
895
- c == sep
900
+ c == SEP
896
901
}
897
902
898
903
/// Returns whether the given byte is a path separator.
899
904
/// Allows both the primary separator '\' and the alternative separator '/'.
900
905
#[ inline]
901
906
pub fn is_sep_byte ( u : & u8 ) -> bool {
902
- * u as char == sep || * u as char == sep2
907
+ * u == SEP_BYTE || * u == SEP2_BYTE
903
908
}
904
909
905
910
/// Returns whether the given byte is a path separator.
906
911
/// Only allows the primary separator '\'; use is_sep_byte to allow '/'.
907
912
#[ inline]
908
913
pub fn is_sep_byte_verbatim ( u : & u8 ) -> bool {
909
- * u as char == sep
914
+ * u == SEP_BYTE
910
915
}
911
916
912
917
/// Prefix types for Path
0 commit comments