@@ -113,7 +113,7 @@ use ops::{self, Deref};
113
113
114
114
use ffi:: { OsStr , OsString } ;
115
115
116
- use self :: platform :: { is_sep_byte, is_verbatim_sep, MAIN_SEP_STR , parse_prefix} ;
116
+ use sys :: path :: { is_sep_byte, is_verbatim_sep, MAIN_SEP_STR , parse_prefix} ;
117
117
118
118
////////////////////////////////////////////////////////////////////////////////
119
119
// GENERAL NOTES
@@ -125,130 +125,6 @@ use self::platform::{is_sep_byte, is_verbatim_sep, MAIN_SEP_STR, parse_prefix};
125
125
// OsStr APIs for parsing, but it will take a while for those to become
126
126
// available.
127
127
128
- ////////////////////////////////////////////////////////////////////////////////
129
- // Platform-specific definitions
130
- ////////////////////////////////////////////////////////////////////////////////
131
-
132
- // The following modules give the most basic tools for parsing paths on various
133
- // platforms. The bulk of the code is devoted to parsing prefixes on Windows.
134
-
135
- #[ cfg( unix) ]
136
- mod platform {
137
- use super :: Prefix ;
138
- use ffi:: OsStr ;
139
-
140
- #[ inline]
141
- pub fn is_sep_byte ( b : u8 ) -> bool {
142
- b == b'/'
143
- }
144
-
145
- #[ inline]
146
- pub fn is_verbatim_sep ( b : u8 ) -> bool {
147
- b == b'/'
148
- }
149
-
150
- pub fn parse_prefix ( _: & OsStr ) -> Option < Prefix > {
151
- None
152
- }
153
-
154
- pub const MAIN_SEP_STR : & ' static str = "/" ;
155
- pub const MAIN_SEP : char = '/' ;
156
- }
157
-
158
- #[ cfg( windows) ]
159
- mod platform {
160
- use ascii:: * ;
161
-
162
- use super :: { os_str_as_u8_slice, u8_slice_as_os_str, Prefix } ;
163
- use ffi:: OsStr ;
164
-
165
- #[ inline]
166
- pub fn is_sep_byte ( b : u8 ) -> bool {
167
- b == b'/' || b == b'\\'
168
- }
169
-
170
- #[ inline]
171
- pub fn is_verbatim_sep ( b : u8 ) -> bool {
172
- b == b'\\'
173
- }
174
-
175
- pub fn parse_prefix < ' a > ( path : & ' a OsStr ) -> Option < Prefix > {
176
- use super :: Prefix :: * ;
177
- unsafe {
178
- // The unsafety here stems from converting between &OsStr and &[u8]
179
- // and back. This is safe to do because (1) we only look at ASCII
180
- // contents of the encoding and (2) new &OsStr values are produced
181
- // only from ASCII-bounded slices of existing &OsStr values.
182
- let mut path = os_str_as_u8_slice ( path) ;
183
-
184
- if path. starts_with ( br"\\" ) {
185
- // \\
186
- path = & path[ 2 ..] ;
187
- if path. starts_with ( br"?\" ) {
188
- // \\?\
189
- path = & path[ 2 ..] ;
190
- if path. starts_with ( br"UNC\" ) {
191
- // \\?\UNC\server\share
192
- path = & path[ 4 ..] ;
193
- let ( server, share) = match parse_two_comps ( path, is_verbatim_sep) {
194
- Some ( ( server, share) ) =>
195
- ( u8_slice_as_os_str ( server) , u8_slice_as_os_str ( share) ) ,
196
- None => ( u8_slice_as_os_str ( path) , u8_slice_as_os_str ( & [ ] ) ) ,
197
- } ;
198
- return Some ( VerbatimUNC ( server, share) ) ;
199
- } else {
200
- // \\?\path
201
- let idx = path. iter ( ) . position ( |& b| b == b'\\' ) ;
202
- if idx == Some ( 2 ) && path[ 1 ] == b':' {
203
- let c = path[ 0 ] ;
204
- if c. is_ascii ( ) && ( c as char ) . is_alphabetic ( ) {
205
- // \\?\C:\ path
206
- return Some ( VerbatimDisk ( c. to_ascii_uppercase ( ) ) ) ;
207
- }
208
- }
209
- let slice = & path[ ..idx. unwrap_or ( path. len ( ) ) ] ;
210
- return Some ( Verbatim ( u8_slice_as_os_str ( slice) ) ) ;
211
- }
212
- } else if path. starts_with ( b".\\ " ) {
213
- // \\.\path
214
- path = & path[ 2 ..] ;
215
- let pos = path. iter ( ) . position ( |& b| b == b'\\' ) ;
216
- let slice = & path[ ..pos. unwrap_or ( path. len ( ) ) ] ;
217
- return Some ( DeviceNS ( u8_slice_as_os_str ( slice) ) ) ;
218
- }
219
- match parse_two_comps ( path, is_sep_byte) {
220
- Some ( ( server, share) ) if !server. is_empty ( ) && !share. is_empty ( ) => {
221
- // \\server\share
222
- return Some ( UNC ( u8_slice_as_os_str ( server) , u8_slice_as_os_str ( share) ) ) ;
223
- }
224
- _ => ( ) ,
225
- }
226
- } else if path. get ( 1 ) == Some ( & b':' ) {
227
- // C:
228
- let c = path[ 0 ] ;
229
- if c. is_ascii ( ) && ( c as char ) . is_alphabetic ( ) {
230
- return Some ( Disk ( c. to_ascii_uppercase ( ) ) ) ;
231
- }
232
- }
233
- return None ;
234
- }
235
-
236
- fn parse_two_comps ( mut path : & [ u8 ] , f : fn ( u8 ) -> bool ) -> Option < ( & [ u8 ] , & [ u8 ] ) > {
237
- let first = match path. iter ( ) . position ( |x| f ( * x) ) {
238
- None => return None ,
239
- Some ( x) => & path[ ..x] ,
240
- } ;
241
- path = & path[ ( first. len ( ) + 1 ) ..] ;
242
- let idx = path. iter ( ) . position ( |x| f ( * x) ) ;
243
- let second = & path[ ..idx. unwrap_or ( path. len ( ) ) ] ;
244
- Some ( ( first, second) )
245
- }
246
- }
247
-
248
- pub const MAIN_SEP_STR : & ' static str = "\\ " ;
249
- pub const MAIN_SEP : char = '\\' ;
250
- }
251
-
252
128
////////////////////////////////////////////////////////////////////////////////
253
129
// Windows Prefixes
254
130
////////////////////////////////////////////////////////////////////////////////
@@ -373,7 +249,7 @@ pub fn is_separator(c: char) -> bool {
373
249
374
250
/// The primary separator for the current platform
375
251
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
376
- pub const MAIN_SEPARATOR : char = platform :: MAIN_SEP ;
252
+ pub const MAIN_SEPARATOR : char = :: sys :: path :: MAIN_SEP ;
377
253
378
254
////////////////////////////////////////////////////////////////////////////////
379
255
// Misc helpers
0 commit comments