@@ -183,7 +183,7 @@ impl GenericPathUnsafe for Path {
183183 None if ".." == self . repr => {
184184 let mut s = str:: with_capacity ( 3 + filename. len ( ) ) ;
185185 s. push_str ( ".." ) ;
186- s. push_char ( sep ) ;
186+ s. push_char ( SEP ) ;
187187 s. push_str ( filename) ;
188188 self . update_normalized ( s) ;
189189 }
@@ -193,7 +193,7 @@ impl GenericPathUnsafe for Path {
193193 Some ( ( _, idxa, end) ) if self . repr . slice ( idxa, end) == ".." => {
194194 let mut s = str:: with_capacity ( end + 1 + filename. len ( ) ) ;
195195 s. push_str ( self . repr . slice_to ( end) ) ;
196- s. push_char ( sep ) ;
196+ s. push_char ( SEP ) ;
197197 s. push_str ( filename) ;
198198 self . update_normalized ( s) ;
199199 }
@@ -206,7 +206,7 @@ impl GenericPathUnsafe for Path {
206206 Some ( ( idxb, _, _) ) => {
207207 let mut s = str:: with_capacity ( idxb + 1 + filename. len ( ) ) ;
208208 s. push_str ( self . repr . slice_to ( idxb) ) ;
209- s. push_char ( sep ) ;
209+ s. push_char ( SEP ) ;
210210 s. push_str ( filename) ;
211211 self . update_normalized ( s) ;
212212 }
@@ -264,8 +264,8 @@ impl GenericPathUnsafe for Path {
264264 // if me is "C:" we don't want to add a path separator
265265 match me. prefix {
266266 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 ) ;
269269 }
270270 _ => ( )
271271 }
@@ -460,7 +460,7 @@ impl GenericPath for Path {
460460 match self . prefix {
461461 Some ( DiskPrefix ) => {
462462 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
464464 }
465465 Some ( _) => true ,
466466 None => false
@@ -501,7 +501,7 @@ impl GenericPath for Path {
501501
502502 fn path_relative_from ( & self , base : & Path ) -> Option < Path > {
503503 fn comp_requires_verbatim ( s : & str ) -> bool {
504- s == "." || s == ".." || s. contains_char ( sep2 )
504+ s == "." || s == ".." || s. contains_char ( SEP2 )
505505 }
506506
507507 if !self . equiv_prefix ( base) {
@@ -619,14 +619,14 @@ impl Path {
619619 let s = match self . prefix {
620620 Some ( _) => {
621621 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 {
623623 self . repr . slice_from ( plen+1 )
624624 } else { self . repr . slice_from ( plen) }
625625 }
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 ) ,
627627 None => self . repr . as_slice ( )
628628 } ;
629- let ret = s. split_terminator ( sep ) . map ( Some ) ;
629+ let ret = s. split_terminator ( SEP ) . map ( Some ) ;
630630 ret
631631 }
632632
@@ -703,7 +703,7 @@ impl Path {
703703 Some ( VerbatimUNCPrefix ( x, 0 ) ) if s. len ( ) == 8 + x => {
704704 // the server component has no trailing '\'
705705 let mut s = s. into_owned ( ) ;
706- s. push_char ( sep ) ;
706+ s. push_char ( SEP ) ;
707707 Some ( s)
708708 }
709709 _ => None
@@ -739,7 +739,7 @@ impl Path {
739739 if is_abs {
740740 // normalize C:/ to C:\
741741 unsafe {
742- str:: raw:: as_owned_vec ( & mut s) [ 2 ] = sep as u8 ;
742+ str:: raw:: as_owned_vec ( & mut s) [ 2 ] = SEP_BYTE ;
743743 }
744744 }
745745 Some ( s)
@@ -761,7 +761,7 @@ impl Path {
761761 }
762762 }
763763 } else if is_abs && comps. is_empty ( ) {
764- Some ( str:: from_char ( sep ) )
764+ Some ( str:: from_char ( SEP ) )
765765 } else {
766766 let prefix_ = s. slice_to ( prefix_len ( prefix) ) ;
767767 let n = prefix_. len ( ) +
@@ -781,7 +781,7 @@ impl Path {
781781 Some ( UNCPrefix ( a, b) ) => {
782782 s. push_str ( "\\ \\ " ) ;
783783 s. push_str ( prefix_. slice ( 2 , a+2 ) ) ;
784- s. push_char ( sep ) ;
784+ s. push_char ( SEP ) ;
785785 s. push_str ( prefix_. slice ( 3 +a, 3 +a+b) ) ;
786786 }
787787 Some ( _) => s. push_str ( prefix_) ,
@@ -795,7 +795,7 @@ impl Path {
795795 }
796796 }
797797 for comp in it {
798- s. push_char ( sep ) ;
798+ s. push_char ( SEP ) ;
799799 s. push_str ( comp) ;
800800 }
801801 Some ( s)
@@ -837,7 +837,7 @@ impl Path {
837837
838838 fn has_nonsemantic_trailing_slash ( & self ) -> bool {
839839 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
841841 }
842842
843843 fn update_normalized < S : Str > ( & mut self , s : S ) {
@@ -877,36 +877,41 @@ pub fn is_verbatim(path: &Path) -> bool {
877877}
878878
879879/// 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 = '/' ;
881886/// The alternative path separator character
882- pub static sep2 : char = '/' ;
887+ pub static SEP2_BYTE : u8 = SEP2 as u8 ;
883888
884889/// Returns whether the given char is a path separator.
885890/// Allows both the primary separator '\' and the alternative separator '/'.
886891#[ inline]
887892pub fn is_sep ( c : char ) -> bool {
888- c == sep || c == sep2
893+ c == SEP || c == SEP2
889894}
890895
891896/// Returns whether the given char is a path separator.
892897/// Only allows the primary separator '\'; use is_sep to allow '/'.
893898#[ inline]
894899pub fn is_sep_verbatim ( c : char ) -> bool {
895- c == sep
900+ c == SEP
896901}
897902
898903/// Returns whether the given byte is a path separator.
899904/// Allows both the primary separator '\' and the alternative separator '/'.
900905#[ inline]
901906pub fn is_sep_byte ( u : & u8 ) -> bool {
902- * u as char == sep || * u as char == sep2
907+ * u == SEP_BYTE || * u == SEP2_BYTE
903908}
904909
905910/// Returns whether the given byte is a path separator.
906911/// Only allows the primary separator '\'; use is_sep_byte to allow '/'.
907912#[ inline]
908913pub fn is_sep_byte_verbatim ( u : & u8 ) -> bool {
909- * u as char == sep
914+ * u == SEP_BYTE
910915}
911916
912917/// Prefix types for Path
0 commit comments