55'use strict' ;
66
77import { isLinux , isWindows } from 'vs/base/common/platform' ;
8+ import { CharCode } from 'vs/base/common/charCode' ;
89
910/**
1011 * The forward slash path separator.
@@ -113,7 +114,7 @@ export function normalize(path: string, toOSPath?: boolean): string {
113114 for ( let end = root . length ; end <= len ; end ++ ) {
114115
115116 // either at the end or at a path-separator character
116- if ( end === len || path . charCodeAt ( end ) === _slash || path . charCodeAt ( end ) === _backslash ) {
117+ if ( end === len || path . charCodeAt ( end ) === CharCode . Slash || path . charCodeAt ( end ) === CharCode . Backslash ) {
117118
118119 if ( streql ( path , start , end , '..' ) ) {
119120 // skip current and remove parent (if there is already something)
@@ -160,28 +161,28 @@ export function getRoot(path: string, sep: string = '/'): string {
160161
161162 let len = path . length ;
162163 let code = path . charCodeAt ( 0 ) ;
163- if ( code === _slash || code === _backslash ) {
164+ if ( code === CharCode . Slash || code === CharCode . Backslash ) {
164165
165166 code = path . charCodeAt ( 1 ) ;
166- if ( code === _slash || code === _backslash ) {
167+ if ( code === CharCode . Slash || code === CharCode . Backslash ) {
167168 // UNC candidate \\localhost\shares\ddd
168169 // ^^^^^^^^^^^^^^^^^^^
169170 code = path . charCodeAt ( 2 ) ;
170- if ( code !== _slash && code !== _backslash ) {
171+ if ( code !== CharCode . Slash && code !== CharCode . Backslash ) {
171172 let pos = 3 ;
172173 let start = pos ;
173174 for ( ; pos < len ; pos ++ ) {
174175 code = path . charCodeAt ( pos ) ;
175- if ( code === _slash || code === _backslash ) {
176+ if ( code === CharCode . Slash || code === CharCode . Backslash ) {
176177 break ;
177178 }
178179 }
179180 code = path . charCodeAt ( pos + 1 ) ;
180- if ( start !== pos && code !== _slash && code !== _backslash ) {
181+ if ( start !== pos && code !== CharCode . Slash && code !== CharCode . Backslash ) {
181182 pos += 1 ;
182183 for ( ; pos < len ; pos ++ ) {
183184 code = path . charCodeAt ( pos ) ;
184- if ( code === _slash || code === _backslash ) {
185+ if ( code === CharCode . Slash || code === CharCode . Backslash ) {
185186 return path . slice ( 0 , pos + 1 ) // consume this separator
186187 . replace ( / [ \\ / ] / g, sep ) ;
187188 }
@@ -194,12 +195,12 @@ export function getRoot(path: string, sep: string = '/'): string {
194195 // ^
195196 return sep ;
196197
197- } else if ( ( code >= _A && code <= _Z ) || ( code >= _a && code <= _z ) ) {
198+ } else if ( ( code >= CharCode . A && code <= CharCode . Z ) || ( code >= CharCode . a && code <= CharCode . z ) ) {
198199 // check for windows drive letter c:\ or c:
199200
200- if ( path . charCodeAt ( 1 ) === _colon ) {
201+ if ( path . charCodeAt ( 1 ) === CharCode . Colon ) {
201202 code = path . charCodeAt ( 2 ) ;
202- if ( code === _slash || code === _backslash ) {
203+ if ( code === CharCode . Slash || code === CharCode . Backslash ) {
203204 // C:\fff
204205 // ^^^
205206 return path . slice ( 0 , 2 ) + sep ;
@@ -219,7 +220,7 @@ export function getRoot(path: string, sep: string = '/'): string {
219220 pos += 3 ; // 3 -> "://".length
220221 for ( ; pos < len ; pos ++ ) {
221222 code = path . charCodeAt ( pos ) ;
222- if ( code === _slash || code === _backslash ) {
223+ if ( code === CharCode . Slash || code === CharCode . Backslash ) {
223224 return path . slice ( 0 , pos + 1 ) ; // consume this separator
224225 }
225226 }
@@ -240,9 +241,9 @@ export const join: (...parts: string[]) => string = function () {
240241 // add the separater between two parts unless
241242 // there already is one
242243 let last = value . charCodeAt ( value . length - 1 ) ;
243- if ( last !== _slash && last !== _backslash ) {
244+ if ( last !== CharCode . Slash && last !== CharCode . Backslash ) {
244245 let next = part . charCodeAt ( 0 ) ;
245- if ( next !== _slash && next !== _backslash ) {
246+ if ( next !== CharCode . Slash && next !== CharCode . Backslash ) {
246247
247248 value += sep ;
248249 }
@@ -274,26 +275,26 @@ export function isUNC(path: string): boolean {
274275 }
275276
276277 let code = path . charCodeAt ( 0 ) ;
277- if ( code !== _backslash ) {
278+ if ( code !== CharCode . Backslash ) {
278279 return false ;
279280 }
280281 code = path . charCodeAt ( 1 ) ;
281- if ( code !== _backslash ) {
282+ if ( code !== CharCode . Backslash ) {
282283 return false ;
283284 }
284285 let pos = 2 ;
285286 let start = pos ;
286287 for ( ; pos < path . length ; pos ++ ) {
287288 code = path . charCodeAt ( pos ) ;
288- if ( code === _backslash ) {
289+ if ( code === CharCode . Backslash ) {
289290 break ;
290291 }
291292 }
292293 if ( start === pos ) {
293294 return false ;
294295 }
295296 code = path . charCodeAt ( pos + 1 ) ;
296- if ( isNaN ( code ) || code === _backslash ) {
297+ if ( isNaN ( code ) || code === CharCode . Backslash ) {
297298 return false ;
298299 }
299300 return true ;
@@ -307,15 +308,6 @@ export function makePosixAbsolute(path: string): string {
307308 return isPosixAbsolute ( normalize ( path ) ) ? path : sep + path ;
308309}
309310
310-
311- const _slash = '/' . charCodeAt ( 0 ) ;
312- const _backslash = '\\' . charCodeAt ( 0 ) ;
313- const _colon = ':' . charCodeAt ( 0 ) ;
314- const _a = 'a' . charCodeAt ( 0 ) ;
315- const _A = 'A' . charCodeAt ( 0 ) ;
316- const _z = 'z' . charCodeAt ( 0 ) ;
317- const _Z = 'Z' . charCodeAt ( 0 ) ;
318-
319311export function isEqualOrParent ( path : string , candidate : string ) : boolean {
320312
321313 if ( path === candidate ) {
@@ -327,7 +319,7 @@ export function isEqualOrParent(path: string, candidate: string): boolean {
327319
328320 let candidateLen = candidate . length ;
329321 let lastCandidateChar = candidate . charCodeAt ( candidateLen - 1 ) ;
330- if ( lastCandidateChar === _slash ) {
322+ if ( lastCandidateChar === CharCode . Slash ) {
331323 candidate = candidate . substring ( 0 , candidateLen - 1 ) ;
332324 candidateLen -= 1 ;
333325 }
@@ -351,7 +343,7 @@ export function isEqualOrParent(path: string, candidate: string): boolean {
351343 }
352344
353345 let char = path . charCodeAt ( candidateLen ) ;
354- return char === _slash ;
346+ return char === CharCode . Slash ;
355347}
356348
357349// Reference: https://en.wikipedia.org/wiki/Filename
0 commit comments