OLD | NEW |
---|---|
(Empty) | |
1 dart_library.library('path', null, /* Imports */[ | |
Jennifer Messerly
2016/05/06 18:53:07
feel free to .gitignore these if you don't want th
Jacob
2016/05/06 19:17:33
Added these to the .gitignore
| |
2 'dart_sdk' | |
3 ], function(exports, dart_sdk) { | |
4 'use strict'; | |
5 const core = dart_sdk.core; | |
6 const dart = dart_sdk.dart; | |
7 const dartx = dart_sdk.dartx; | |
8 const path$ = Object.create(null); | |
9 const src__context = Object.create(null); | |
10 const src__style = Object.create(null); | |
11 const src__style__posix = Object.create(null); | |
12 const src__style__url = Object.create(null); | |
13 const src__style__windows = Object.create(null); | |
14 const src__utils = Object.create(null); | |
15 const src__characters = Object.create(null); | |
16 const src__parsed_path = Object.create(null); | |
17 const src__path_exception = Object.create(null); | |
18 const src__internal_style = Object.create(null); | |
19 dart.defineLazy(path$, { | |
20 get posix() { | |
21 return src__context.Context.new({style: src__style.Style.posix}); | |
22 } | |
23 }); | |
24 dart.defineLazy(path$, { | |
25 get windows() { | |
26 return src__context.Context.new({style: src__style.Style.windows}); | |
27 } | |
28 }); | |
29 dart.defineLazy(path$, { | |
30 get url() { | |
31 return src__context.Context.new({style: src__style.Style.url}); | |
32 } | |
33 }); | |
34 dart.defineLazy(path$, { | |
35 get context() { | |
36 return src__context.createInternal(); | |
37 } | |
38 }); | |
39 dart.copyProperties(path$, { | |
40 get style() { | |
41 return path$.context.style; | |
42 } | |
43 }); | |
44 dart.copyProperties(path$, { | |
45 get current() { | |
46 let uri = core.Uri.base; | |
47 if (dart.equals(uri, path$._currentUriBase)) return path$._current; | |
48 path$._currentUriBase = uri; | |
49 if (dart.equals(src__style.Style.platform, src__style.Style.url)) { | |
50 path$._current = dart.toString(uri.resolve('.')); | |
51 return path$._current; | |
52 } else { | |
53 let path = uri.toFilePath(); | |
54 let lastIndex = dart.notNull(path[dartx.length]) - 1; | |
55 dart.assert(path[dartx.get](lastIndex) == '/' || path[dartx.get](lastInd ex) == '\\'); | |
56 path$._current = path[dartx.substring](0, lastIndex); | |
57 return path$._current; | |
58 } | |
59 } | |
60 }); | |
61 path$._currentUriBase = null; | |
62 path$._current = null; | |
63 dart.copyProperties(path$, { | |
64 get separator() { | |
65 return path$.context.separator; | |
66 } | |
67 }); | |
68 path$.absolute = function(part1, part2, part3, part4, part5, part6, part7) { | |
69 if (part2 === void 0) part2 = null; | |
70 if (part3 === void 0) part3 = null; | |
71 if (part4 === void 0) part4 = null; | |
72 if (part5 === void 0) part5 = null; | |
73 if (part6 === void 0) part6 = null; | |
74 if (part7 === void 0) part7 = null; | |
75 return path$.context.absolute(part1, part2, part3, part4, part5, part6, part 7); | |
76 }; | |
77 dart.fn(path$.absolute, core.String, [core.String], [core.String, core.String, core.String, core.String, core.String, core.String]); | |
78 path$.basename = function(path) { | |
79 return path$.context.basename(path); | |
80 }; | |
81 dart.fn(path$.basename, core.String, [core.String]); | |
82 path$.basenameWithoutExtension = function(path) { | |
83 return path$.context.basenameWithoutExtension(path); | |
84 }; | |
85 dart.fn(path$.basenameWithoutExtension, core.String, [core.String]); | |
86 path$.dirname = function(path) { | |
87 return path$.context.dirname(path); | |
88 }; | |
89 dart.fn(path$.dirname, core.String, [core.String]); | |
90 path$.extension = function(path) { | |
91 return path$.context.extension(path); | |
92 }; | |
93 dart.fn(path$.extension, core.String, [core.String]); | |
94 path$.rootPrefix = function(path) { | |
95 return path$.context.rootPrefix(path); | |
96 }; | |
97 dart.fn(path$.rootPrefix, core.String, [core.String]); | |
98 path$.isAbsolute = function(path) { | |
99 return path$.context.isAbsolute(path); | |
100 }; | |
101 dart.fn(path$.isAbsolute, core.bool, [core.String]); | |
102 path$.isRelative = function(path) { | |
103 return path$.context.isRelative(path); | |
104 }; | |
105 dart.fn(path$.isRelative, core.bool, [core.String]); | |
106 path$.isRootRelative = function(path) { | |
107 return path$.context.isRootRelative(path); | |
108 }; | |
109 dart.fn(path$.isRootRelative, core.bool, [core.String]); | |
110 path$.join = function(part1, part2, part3, part4, part5, part6, part7, part8) { | |
111 if (part2 === void 0) part2 = null; | |
112 if (part3 === void 0) part3 = null; | |
113 if (part4 === void 0) part4 = null; | |
114 if (part5 === void 0) part5 = null; | |
115 if (part6 === void 0) part6 = null; | |
116 if (part7 === void 0) part7 = null; | |
117 if (part8 === void 0) part8 = null; | |
118 return path$.context.join(part1, part2, part3, part4, part5, part6, part7, p art8); | |
119 }; | |
120 dart.fn(path$.join, core.String, [core.String], [core.String, core.String, cor e.String, core.String, core.String, core.String, core.String]); | |
121 path$.joinAll = function(parts) { | |
122 return path$.context.joinAll(parts); | |
123 }; | |
124 dart.fn(path$.joinAll, core.String, [core.Iterable$(core.String)]); | |
125 path$.split = function(path) { | |
126 return path$.context.split(path); | |
127 }; | |
128 dart.fn(path$.split, core.List$(core.String), [core.String]); | |
129 path$.normalize = function(path) { | |
130 return path$.context.normalize(path); | |
131 }; | |
132 dart.fn(path$.normalize, core.String, [core.String]); | |
133 path$.relative = function(path, opts) { | |
134 let from = opts && 'from' in opts ? opts.from : null; | |
135 return path$.context.relative(path, {from: from}); | |
136 }; | |
137 dart.fn(path$.relative, core.String, [core.String], {from: core.String}); | |
138 path$.isWithin = function(parent, child) { | |
139 return path$.context.isWithin(parent, child); | |
140 }; | |
141 dart.fn(path$.isWithin, core.bool, [core.String, core.String]); | |
142 path$.withoutExtension = function(path) { | |
143 return path$.context.withoutExtension(path); | |
144 }; | |
145 dart.fn(path$.withoutExtension, core.String, [core.String]); | |
146 path$.fromUri = function(uri) { | |
147 return path$.context.fromUri(uri); | |
148 }; | |
149 dart.fn(path$.fromUri, core.String, [dart.dynamic]); | |
150 path$.toUri = function(path) { | |
151 return path$.context.toUri(path); | |
152 }; | |
153 dart.fn(path$.toUri, core.Uri, [core.String]); | |
154 path$.prettyUri = function(uri) { | |
155 return path$.context.prettyUri(uri); | |
156 }; | |
157 dart.fn(path$.prettyUri, core.String, [dart.dynamic]); | |
158 const _current = Symbol('_current'); | |
159 const _parse = Symbol('_parse'); | |
160 const _needsNormalization = Symbol('_needsNormalization'); | |
161 const _isWithinFast = Symbol('_isWithinFast'); | |
162 const _pathDirection = Symbol('_pathDirection'); | |
163 src__context.Context = class Context extends core.Object { | |
164 static new(opts) { | |
165 let style = opts && 'style' in opts ? opts.style : null; | |
166 let current = opts && 'current' in opts ? opts.current : null; | |
167 if (current == null) { | |
168 if (style == null) { | |
169 current = path$.current; | |
170 } else { | |
171 current = "."; | |
172 } | |
173 } | |
174 if (style == null) { | |
175 style = src__style.Style.platform; | |
176 } else if (!dart.is(style, src__internal_style.InternalStyle)) { | |
177 dart.throw(new core.ArgumentError("Only styles defined by the path packa ge are " + "allowed.")); | |
178 } | |
179 return new src__context.Context._(dart.as(style, src__internal_style.Inter nalStyle), current); | |
180 } | |
181 _internal() { | |
182 this.style = dart.as(src__style.Style.platform, src__internal_style.Intern alStyle); | |
183 this[_current] = null; | |
184 } | |
185 _(style, current) { | |
186 this.style = style; | |
187 this[_current] = current; | |
188 } | |
189 get current() { | |
190 return this[_current] != null ? this[_current] : path$.current; | |
191 } | |
192 get separator() { | |
193 return this.style.separator; | |
194 } | |
195 absolute(part1, part2, part3, part4, part5, part6, part7) { | |
196 if (part2 === void 0) part2 = null; | |
197 if (part3 === void 0) part3 = null; | |
198 if (part4 === void 0) part4 = null; | |
199 if (part5 === void 0) part5 = null; | |
200 if (part6 === void 0) part6 = null; | |
201 if (part7 === void 0) part7 = null; | |
202 src__context._validateArgList("absolute", dart.list([part1, part2, part3, part4, part5, part6, part7], core.String)); | |
203 if (part2 == null && dart.notNull(this.isAbsolute(part1)) && !dart.notNull (this.isRootRelative(part1))) { | |
204 return part1; | |
205 } | |
206 return this.join(this.current, part1, part2, part3, part4, part5, part6, p art7); | |
207 } | |
208 basename(path) { | |
209 return this[_parse](path).basename; | |
210 } | |
211 basenameWithoutExtension(path) { | |
212 return this[_parse](path).basenameWithoutExtension; | |
213 } | |
214 dirname(path) { | |
215 let parsed = this[_parse](path); | |
216 parsed.removeTrailingSeparators(); | |
217 if (dart.notNull(parsed.parts[dartx.isEmpty])) return parsed.root == null ? '.' : parsed.root; | |
218 if (parsed.parts[dartx.length] == 1) { | |
219 return parsed.root == null ? '.' : parsed.root; | |
220 } | |
221 parsed.parts[dartx.removeLast](); | |
222 parsed.separators[dartx.removeLast](); | |
223 parsed.removeTrailingSeparators(); | |
224 return dart.toString(parsed); | |
225 } | |
226 extension(path) { | |
227 return this[_parse](path).extension; | |
228 } | |
229 rootPrefix(path) { | |
230 return path[dartx.substring](0, this.style.rootLength(path)); | |
231 } | |
232 isAbsolute(path) { | |
233 return dart.notNull(this.style.rootLength(path)) > 0; | |
234 } | |
235 isRelative(path) { | |
236 return !dart.notNull(this.isAbsolute(path)); | |
237 } | |
238 isRootRelative(path) { | |
239 return this.style.isRootRelative(path); | |
240 } | |
241 join(part1, part2, part3, part4, part5, part6, part7, part8) { | |
242 if (part2 === void 0) part2 = null; | |
243 if (part3 === void 0) part3 = null; | |
244 if (part4 === void 0) part4 = null; | |
245 if (part5 === void 0) part5 = null; | |
246 if (part6 === void 0) part6 = null; | |
247 if (part7 === void 0) part7 = null; | |
248 if (part8 === void 0) part8 = null; | |
249 let parts = dart.list([part1, part2, part3, part4, part5, part6, part7, pa rt8], core.String); | |
250 src__context._validateArgList("join", parts); | |
251 return this.joinAll(parts[dartx.where](dart.fn(part => part != null, core. bool, [core.String]))); | |
252 } | |
253 joinAll(parts) { | |
254 let buffer = new core.StringBuffer(); | |
255 let needsSeparator = false; | |
256 let isAbsoluteAndNotRootRelative = false; | |
257 for (let part of parts[dartx.where](dart.fn(part => part != '', core.bool, [core.String]))) { | |
258 if (dart.notNull(this.isRootRelative(part)) && isAbsoluteAndNotRootRelat ive) { | |
259 let parsed = this[_parse](part); | |
260 parsed.root = this.rootPrefix(buffer.toString()); | |
261 if (dart.notNull(this.style.needsSeparator(parsed.root))) { | |
262 parsed.separators[dartx.set](0, this.style.separator); | |
263 } | |
264 buffer.clear(); | |
265 buffer.write(dart.toString(parsed)); | |
266 } else if (dart.notNull(this.isAbsolute(part))) { | |
267 isAbsoluteAndNotRootRelative = !dart.notNull(this.isRootRelative(part) ); | |
268 buffer.clear(); | |
269 buffer.write(part); | |
270 } else { | |
271 if (dart.notNull(part[dartx.length]) > 0 && dart.notNull(this.style.co ntainsSeparator(part[dartx.get](0)))) { | |
272 } else if (dart.notNull(needsSeparator)) { | |
273 buffer.write(this.separator); | |
274 } | |
275 buffer.write(part); | |
276 } | |
277 needsSeparator = this.style.needsSeparator(part); | |
278 } | |
279 return buffer.toString(); | |
280 } | |
281 split(path) { | |
282 let parsed = this[_parse](path); | |
283 parsed.parts = parsed.parts[dartx.where](dart.fn(part => !dart.notNull(par t[dartx.isEmpty]), core.bool, [core.String]))[dartx.toList](); | |
284 if (parsed.root != null) parsed.parts[dartx.insert](0, parsed.root); | |
285 return parsed.parts; | |
286 } | |
287 normalize(path) { | |
288 if (!dart.notNull(this[_needsNormalization](path))) return path; | |
289 let parsed = this[_parse](path); | |
290 parsed.normalize(); | |
291 return dart.toString(parsed); | |
292 } | |
293 [_needsNormalization](path) { | |
294 let start = 0; | |
295 let codeUnits = path[dartx.codeUnits]; | |
296 let previousPrevious = null; | |
297 let previous = null; | |
298 let root = this.style.rootLength(path); | |
299 if (root != 0) { | |
300 start = root; | |
301 previous = src__characters.SLASH; | |
302 if (dart.equals(this.style, src__style.Style.windows)) { | |
303 for (let i = 0; i < dart.notNull(root); i++) { | |
304 if (codeUnits[dartx.get](i) == src__characters.SLASH) return true; | |
305 } | |
306 } | |
307 } | |
308 for (let i = start; dart.notNull(i) < dart.notNull(codeUnits[dartx.length] ); i = dart.notNull(i) + 1) { | |
309 let codeUnit = codeUnits[dartx.get](i); | |
310 if (dart.notNull(this.style.isSeparator(codeUnit))) { | |
311 if (dart.equals(this.style, src__style.Style.windows) && codeUnit == s rc__characters.SLASH) return true; | |
312 if (previous != null && dart.notNull(this.style.isSeparator(dart.as(pr evious, core.int)))) return true; | |
313 if (dart.equals(previous, src__characters.PERIOD) && (previousPrevious == null || dart.equals(previousPrevious, src__characters.PERIOD) || dart.notNul l(this.style.isSeparator(dart.as(previousPrevious, core.int))))) { | |
314 return true; | |
315 } | |
316 } | |
317 previousPrevious = previous; | |
318 previous = codeUnit; | |
319 } | |
320 if (previous == null) return true; | |
321 if (dart.notNull(this.style.isSeparator(dart.as(previous, core.int)))) ret urn true; | |
322 if (dart.equals(previous, src__characters.PERIOD) && (previousPrevious == null || dart.equals(previousPrevious, src__characters.SLASH) || dart.equals(prev iousPrevious, src__characters.PERIOD))) { | |
323 return true; | |
324 } | |
325 return false; | |
326 } | |
327 relative(path, opts) { | |
328 let from = opts && 'from' in opts ? opts.from : null; | |
329 if (from == null && dart.notNull(this.isRelative(path))) return this.norma lize(path); | |
330 from = from == null ? this.current : this.absolute(from); | |
331 if (dart.notNull(this.isRelative(from)) && dart.notNull(this.isAbsolute(pa th))) { | |
332 return this.normalize(path); | |
333 } | |
334 if (dart.notNull(this.isRelative(path)) || dart.notNull(this.isRootRelativ e(path))) { | |
335 path = this.absolute(path); | |
336 } | |
337 if (dart.notNull(this.isRelative(path)) && dart.notNull(this.isAbsolute(fr om))) { | |
338 dart.throw(new src__path_exception.PathException(`Unable to find a path to "${path}" from "${from}".`)); | |
339 } | |
340 let fromParsed = this[_parse](from); | |
341 fromParsed.normalize(); | |
342 let pathParsed = this[_parse](path); | |
343 pathParsed.normalize(); | |
344 if (dart.notNull(fromParsed.parts[dartx.length]) > 0 && fromParsed.parts[d artx.get](0) == '.') { | |
345 return pathParsed.toString(); | |
346 } | |
347 if (fromParsed.root != pathParsed.root && (fromParsed.root == null || path Parsed.root == null || fromParsed.root[dartx.toLowerCase]()[dartx.replaceAll]('/ ', '\\') != pathParsed.root[dartx.toLowerCase]()[dartx.replaceAll]('/', '\\'))) { | |
348 return pathParsed.toString(); | |
349 } | |
350 while (dart.notNull(fromParsed.parts[dartx.length]) > 0 && dart.notNull(pa thParsed.parts[dartx.length]) > 0 && fromParsed.parts[dartx.get](0) == pathParse d.parts[dartx.get](0)) { | |
351 fromParsed.parts[dartx.removeAt](0); | |
352 fromParsed.separators[dartx.removeAt](1); | |
353 pathParsed.parts[dartx.removeAt](0); | |
354 pathParsed.separators[dartx.removeAt](1); | |
355 } | |
356 if (dart.notNull(fromParsed.parts[dartx.length]) > 0 && fromParsed.parts[d artx.get](0) == '..') { | |
357 dart.throw(new src__path_exception.PathException(`Unable to find a path to "${path}" from "${from}".`)); | |
358 } | |
359 pathParsed.parts[dartx.insertAll](0, core.List$(core.String).filled(fromPa rsed.parts[dartx.length], '..')); | |
360 pathParsed.separators[dartx.set](0, ''); | |
361 pathParsed.separators[dartx.insertAll](1, core.List$(core.String).filled(f romParsed.parts[dartx.length], this.style.separator)); | |
362 if (pathParsed.parts[dartx.length] == 0) return '.'; | |
363 if (dart.notNull(pathParsed.parts[dartx.length]) > 1 && pathParsed.parts[d artx.last] == '.') { | |
364 pathParsed.parts[dartx.removeLast](); | |
365 let _ = pathParsed.separators; | |
366 _[dartx.removeLast](); | |
367 _[dartx.removeLast](); | |
368 _[dartx.add](''); | |
369 } | |
370 pathParsed.root = ''; | |
371 pathParsed.removeTrailingSeparators(); | |
372 return pathParsed.toString(); | |
373 } | |
374 isWithin(parent, child) { | |
375 let parentIsAbsolute = this.isAbsolute(parent); | |
376 let childIsAbsolute = this.isAbsolute(child); | |
377 if (dart.notNull(parentIsAbsolute) && !dart.notNull(childIsAbsolute)) { | |
378 child = this.absolute(child); | |
379 if (dart.notNull(this.style.isRootRelative(parent))) parent = this.absol ute(parent); | |
380 } else if (dart.notNull(childIsAbsolute) && !dart.notNull(parentIsAbsolute )) { | |
381 parent = this.absolute(parent); | |
382 if (dart.notNull(this.style.isRootRelative(child))) child = this.absolut e(child); | |
383 } else if (dart.notNull(childIsAbsolute) && dart.notNull(parentIsAbsolute) ) { | |
384 let childIsRootRelative = this.style.isRootRelative(child); | |
385 let parentIsRootRelative = this.style.isRootRelative(parent); | |
386 if (dart.notNull(childIsRootRelative) && !dart.notNull(parentIsRootRelat ive)) { | |
387 child = this.absolute(child); | |
388 } else if (dart.notNull(parentIsRootRelative) && !dart.notNull(childIsRo otRelative)) { | |
389 parent = this.absolute(parent); | |
390 } | |
391 } | |
392 let fastResult = this[_isWithinFast](parent, child); | |
393 if (fastResult != null) return fastResult; | |
394 let relative = null; | |
395 try { | |
396 relative = this.relative(child, {from: parent}); | |
397 } catch (_) { | |
398 if (dart.is(_, src__path_exception.PathException)) { | |
399 return false; | |
400 } else | |
401 throw _; | |
402 } | |
403 | |
404 let parts = this.split(dart.as(relative, core.String)); | |
405 return dart.notNull(this.isRelative(dart.as(relative, core.String))) && pa rts[dartx.first] != '..' && parts[dartx.first] != '.'; | |
406 } | |
407 [_isWithinFast](parent, child) { | |
408 if (parent == '.') parent = ''; | |
409 let parentRootLength = this.style.rootLength(parent); | |
410 let childRootLength = this.style.rootLength(child); | |
411 if (parentRootLength != childRootLength) return false; | |
412 let parentCodeUnits = parent[dartx.codeUnits]; | |
413 let childCodeUnits = child[dartx.codeUnits]; | |
414 for (let i = 0; i < dart.notNull(parentRootLength); i++) { | |
415 let parentCodeUnit = parentCodeUnits[dartx.get](i); | |
416 let childCodeUnit = childCodeUnits[dartx.get](i); | |
417 if (parentCodeUnit == childCodeUnit) continue; | |
418 if (!dart.notNull(this.style.isSeparator(parentCodeUnit)) || !dart.notNu ll(this.style.isSeparator(childCodeUnit))) { | |
419 return false; | |
420 } | |
421 } | |
422 let lastCodeUnit = src__characters.SLASH; | |
423 let parentIndex = parentRootLength; | |
424 let childIndex = childRootLength; | |
425 while (dart.notNull(parentIndex) < dart.notNull(parent[dartx.length]) && d art.notNull(childIndex) < dart.notNull(child[dartx.length])) { | |
426 let parentCodeUnit = parentCodeUnits[dartx.get](parentIndex); | |
427 let childCodeUnit = childCodeUnits[dartx.get](childIndex); | |
428 if (parentCodeUnit == childCodeUnit) { | |
429 lastCodeUnit = parentCodeUnit; | |
430 parentIndex = dart.notNull(parentIndex) + 1; | |
431 childIndex = dart.notNull(childIndex) + 1; | |
432 continue; | |
433 } | |
434 let parentIsSeparator = this.style.isSeparator(parentCodeUnit); | |
435 let childIsSeparator = this.style.isSeparator(childCodeUnit); | |
436 if (dart.notNull(parentIsSeparator) && dart.notNull(childIsSeparator)) { | |
437 lastCodeUnit = parentCodeUnit; | |
438 parentIndex = dart.notNull(parentIndex) + 1; | |
439 childIndex = dart.notNull(childIndex) + 1; | |
440 continue; | |
441 } | |
442 if (dart.notNull(parentIsSeparator) && dart.notNull(this.style.isSeparat or(lastCodeUnit))) { | |
443 parentIndex = dart.notNull(parentIndex) + 1; | |
444 continue; | |
445 } else if (dart.notNull(childIsSeparator) && dart.notNull(this.style.isS eparator(lastCodeUnit))) { | |
446 childIndex = dart.notNull(childIndex) + 1; | |
447 continue; | |
448 } | |
449 if (parentCodeUnit == src__characters.PERIOD) { | |
450 if (dart.notNull(this.style.isSeparator(lastCodeUnit))) { | |
451 parentIndex = dart.notNull(parentIndex) + 1; | |
452 if (parentIndex == parent[dartx.length]) break; | |
453 parentCodeUnit = parentCodeUnits[dartx.get](parentIndex); | |
454 if (dart.notNull(this.style.isSeparator(parentCodeUnit))) { | |
455 parentIndex = dart.notNull(parentIndex) + 1; | |
456 continue; | |
457 } | |
458 if (parentCodeUnit == src__characters.PERIOD) { | |
459 parentIndex = dart.notNull(parentIndex) + 1; | |
460 if (parentIndex == parent[dartx.length] || dart.notNull(this.style .isSeparator(parentCodeUnits[dartx.get](parentIndex)))) { | |
461 return null; | |
462 } | |
463 } | |
464 } | |
465 } | |
466 if (childCodeUnit == src__characters.PERIOD) { | |
467 if (dart.notNull(this.style.isSeparator(lastCodeUnit))) { | |
468 childIndex = dart.notNull(childIndex) + 1; | |
469 if (childIndex == child[dartx.length]) break; | |
470 childCodeUnit = childCodeUnits[dartx.get](childIndex); | |
471 if (dart.notNull(this.style.isSeparator(childCodeUnit))) { | |
472 childIndex = dart.notNull(childIndex) + 1; | |
473 continue; | |
474 } | |
475 if (childCodeUnit == src__characters.PERIOD) { | |
476 childIndex = dart.notNull(childIndex) + 1; | |
477 if (childIndex == child[dartx.length] || dart.notNull(this.style.i sSeparator(childCodeUnits[dartx.get](childIndex)))) { | |
478 return null; | |
479 } | |
480 } | |
481 } | |
482 } | |
483 let childDirection = this[_pathDirection](childCodeUnits, childIndex); | |
484 if (!dart.equals(childDirection, src__context._PathDirection.belowRoot)) return null; | |
485 let parentDirection = this[_pathDirection](parentCodeUnits, parentIndex) ; | |
486 if (!dart.equals(parentDirection, src__context._PathDirection.belowRoot) ) return null; | |
487 return false; | |
488 } | |
489 if (childIndex == child[dartx.length]) { | |
490 let direction = this[_pathDirection](parentCodeUnits, parentIndex); | |
491 return dart.equals(direction, src__context._PathDirection.aboveRoot) ? n ull : false; | |
492 } | |
493 let direction = this[_pathDirection](childCodeUnits, childIndex); | |
494 if (dart.equals(direction, src__context._PathDirection.atRoot)) return fal se; | |
495 if (dart.equals(direction, src__context._PathDirection.aboveRoot)) return null; | |
496 return dart.notNull(this.style.isSeparator(childCodeUnits[dartx.get](child Index))) || dart.notNull(this.style.isSeparator(lastCodeUnit)); | |
497 } | |
498 [_pathDirection](codeUnits, index) { | |
499 let depth = 0; | |
500 let reachedRoot = false; | |
501 let i = index; | |
502 while (dart.notNull(i) < dart.notNull(codeUnits[dartx.length])) { | |
503 while (dart.notNull(i) < dart.notNull(codeUnits[dartx.length]) && dart.n otNull(this.style.isSeparator(codeUnits[dartx.get](i)))) { | |
504 i = dart.notNull(i) + 1; | |
505 } | |
506 if (i == codeUnits[dartx.length]) break; | |
507 let start = i; | |
508 while (dart.notNull(i) < dart.notNull(codeUnits[dartx.length]) && !dart. notNull(this.style.isSeparator(codeUnits[dartx.get](i)))) { | |
509 i = dart.notNull(i) + 1; | |
510 } | |
511 if (dart.notNull(i) - dart.notNull(start) == 1 && codeUnits[dartx.get](s tart) == src__characters.PERIOD) { | |
512 } else if (dart.notNull(i) - dart.notNull(start) == 2 && codeUnits[dartx .get](start) == src__characters.PERIOD && codeUnits[dartx.get](dart.notNull(star t) + 1) == src__characters.PERIOD) { | |
513 depth--; | |
514 if (depth < 0) break; | |
515 if (depth == 0) reachedRoot = true; | |
516 } else { | |
517 depth++; | |
518 } | |
519 if (i == codeUnits[dartx.length]) break; | |
520 i = dart.notNull(i) + 1; | |
521 } | |
522 if (depth < 0) return src__context._PathDirection.aboveRoot; | |
523 if (depth == 0) return src__context._PathDirection.atRoot; | |
524 if (reachedRoot) return src__context._PathDirection.reachesRoot; | |
525 return src__context._PathDirection.belowRoot; | |
526 } | |
527 withoutExtension(path) { | |
528 let parsed = this[_parse](path); | |
529 for (let i = dart.notNull(parsed.parts[dartx.length]) - 1; i >= 0; i--) { | |
530 if (!dart.notNull(parsed.parts[dartx.get](i)[dartx.isEmpty])) { | |
531 parsed.parts[dartx.set](i, parsed.basenameWithoutExtension); | |
532 break; | |
533 } | |
534 } | |
535 return dart.toString(parsed); | |
536 } | |
537 fromUri(uri) { | |
538 if (typeof uri == 'string') uri = core.Uri.parse(dart.as(uri, core.String) ); | |
539 return this.style.pathFromUri(dart.as(uri, core.Uri)); | |
540 } | |
541 toUri(path) { | |
542 if (dart.notNull(this.isRelative(path))) { | |
543 return this.style.relativePathToUri(path); | |
544 } else { | |
545 return this.style.absolutePathToUri(this.join(this.current, path)); | |
546 } | |
547 } | |
548 prettyUri(uri) { | |
549 if (typeof uri == 'string') uri = core.Uri.parse(dart.as(uri, core.String) ); | |
550 if (dart.equals(dart.dload(uri, 'scheme'), 'file') && dart.equals(this.sty le, src__style.Style.url)) return dart.toString(uri); | |
551 if (!dart.equals(dart.dload(uri, 'scheme'), 'file') && !dart.equals(dart.d load(uri, 'scheme'), '') && !dart.equals(this.style, src__style.Style.url)) { | |
552 return dart.toString(uri); | |
553 } | |
554 let path = this.normalize(this.fromUri(uri)); | |
555 let rel = this.relative(path); | |
556 return dart.notNull(this.split(rel)[dartx.length]) > dart.notNull(this.spl it(path)[dartx.length]) ? path : rel; | |
557 } | |
558 [_parse](path) { | |
559 return src__parsed_path.ParsedPath.parse(path, this.style); | |
560 } | |
561 }; | |
562 dart.defineNamedConstructor(src__context.Context, '_internal'); | |
563 dart.defineNamedConstructor(src__context.Context, '_'); | |
564 dart.setSignature(src__context.Context, { | |
565 constructors: () => ({ | |
566 new: [src__context.Context, [], {style: src__style.Style, current: core.St ring}], | |
567 _internal: [src__context.Context, []], | |
568 _: [src__context.Context, [src__internal_style.InternalStyle, core.String] ] | |
569 }), | |
570 methods: () => ({ | |
571 absolute: [core.String, [core.String], [core.String, core.String, core.Str ing, core.String, core.String, core.String]], | |
572 basename: [core.String, [core.String]], | |
573 basenameWithoutExtension: [core.String, [core.String]], | |
574 dirname: [core.String, [core.String]], | |
575 extension: [core.String, [core.String]], | |
576 rootPrefix: [core.String, [core.String]], | |
577 isAbsolute: [core.bool, [core.String]], | |
578 isRelative: [core.bool, [core.String]], | |
579 isRootRelative: [core.bool, [core.String]], | |
580 join: [core.String, [core.String], [core.String, core.String, core.String, core.String, core.String, core.String, core.String]], | |
581 joinAll: [core.String, [core.Iterable$(core.String)]], | |
582 split: [core.List$(core.String), [core.String]], | |
583 normalize: [core.String, [core.String]], | |
584 [_needsNormalization]: [core.bool, [core.String]], | |
585 relative: [core.String, [core.String], {from: core.String}], | |
586 isWithin: [core.bool, [core.String, core.String]], | |
587 [_isWithinFast]: [core.bool, [core.String, core.String]], | |
588 [_pathDirection]: [src__context._PathDirection, [core.List$(core.int), cor e.int]], | |
589 withoutExtension: [core.String, [core.String]], | |
590 fromUri: [core.String, [dart.dynamic]], | |
591 toUri: [core.Uri, [core.String]], | |
592 prettyUri: [core.String, [dart.dynamic]], | |
593 [_parse]: [src__parsed_path.ParsedPath, [core.String]] | |
594 }) | |
595 }); | |
596 path$.Context = src__context.Context; | |
597 src__path_exception.PathException = class PathException extends core.Object { | |
598 PathException(message) { | |
599 this.message = message; | |
600 } | |
601 toString() { | |
602 return `PathException: ${this.message}`; | |
603 } | |
604 }; | |
605 src__path_exception.PathException[dart.implements] = () => [core.Exception]; | |
606 dart.setSignature(src__path_exception.PathException, { | |
607 constructors: () => ({PathException: [src__path_exception.PathException, [co re.String]]}) | |
608 }); | |
609 path$.PathException = src__path_exception.PathException; | |
610 src__style.Style = class Style extends core.Object { | |
611 static _getPlatformStyle() { | |
612 if (core.Uri.base.scheme != 'file') return src__style.Style.url; | |
613 if (!dart.notNull(core.Uri.base.path[dartx.endsWith]('/'))) return src__st yle.Style.url; | |
614 if (core.Uri.new({path: 'a/b'}).toFilePath() == 'a\\b') return src__style. Style.windows; | |
615 return src__style.Style.posix; | |
616 } | |
617 get context() { | |
618 return src__context.Context.new({style: this}); | |
619 } | |
620 toString() { | |
621 return this.name; | |
622 } | |
623 }; | |
624 dart.setSignature(src__style.Style, { | |
625 statics: () => ({_getPlatformStyle: [src__style.Style, []]}), | |
626 names: ['_getPlatformStyle'] | |
627 }); | |
628 dart.defineLazy(src__style.Style, { | |
629 get posix() { | |
630 return new src__style__posix.PosixStyle(); | |
631 }, | |
632 get windows() { | |
633 return new src__style__windows.WindowsStyle(); | |
634 }, | |
635 get url() { | |
636 return new src__style__url.UrlStyle(); | |
637 }, | |
638 get platform() { | |
639 return src__style.Style._getPlatformStyle(); | |
640 } | |
641 }); | |
642 path$.Style = src__style.Style; | |
643 src__context.createInternal = function() { | |
644 return new src__context.Context._internal(); | |
645 }; | |
646 dart.fn(src__context.createInternal, src__context.Context, []); | |
647 src__context._validateArgList = function(method, args) { | |
648 for (let i = 1; i < dart.notNull(args[dartx.length]); i++) { | |
649 if (args[dartx.get](i) == null || args[dartx.get](i - 1) != null) continue ; | |
650 let numArgs = null; | |
651 for (numArgs = args[dartx.length]; dart.notNull(dart.as(dart.dsend(numArgs , '>=', 1), core.bool)); numArgs = dart.dsend(numArgs, '-', 1)) { | |
652 if (args[dartx.get](dart.as(dart.dsend(numArgs, '-', 1), core.int)) != n ull) break; | |
653 } | |
654 let message = new core.StringBuffer(); | |
655 message.write(`${method}(`); | |
656 message.write(args[dartx.take](dart.as(numArgs, core.int))[dartx.map](core .String)(dart.fn(arg => arg == null ? "null" : `"${arg}"`, core.String, [core.St ring]))[dartx.join](", ")); | |
657 message.write(`): part ${i - 1} was null, but part ${i} was not.`); | |
658 dart.throw(new core.ArgumentError(message.toString())); | |
659 } | |
660 }; | |
661 dart.fn(src__context._validateArgList, dart.dynamic, [core.String, core.List$( core.String)]); | |
662 src__context._PathDirection = class _PathDirection extends core.Object { | |
663 _PathDirection(name) { | |
664 this.name = name; | |
665 } | |
666 toString() { | |
667 return this.name; | |
668 } | |
669 }; | |
670 dart.setSignature(src__context._PathDirection, { | |
671 constructors: () => ({_PathDirection: [src__context._PathDirection, [core.St ring]]}) | |
672 }); | |
673 dart.defineLazy(src__context._PathDirection, { | |
674 get aboveRoot() { | |
675 return dart.const(new src__context._PathDirection("above root")); | |
676 }, | |
677 get atRoot() { | |
678 return dart.const(new src__context._PathDirection("at root")); | |
679 }, | |
680 get reachesRoot() { | |
681 return dart.const(new src__context._PathDirection("reaches root")); | |
682 }, | |
683 get belowRoot() { | |
684 return dart.const(new src__context._PathDirection("below root")); | |
685 } | |
686 }); | |
687 src__internal_style.InternalStyle = class InternalStyle extends src__style.Sty le { | |
688 getRoot(path) { | |
689 let length = this.rootLength(path); | |
690 if (dart.notNull(length) > 0) return path[dartx.substring](0, length); | |
691 return dart.notNull(this.isRootRelative(path)) ? path[dartx.get](0) : null ; | |
692 } | |
693 relativePathToUri(path) { | |
694 let segments = this.context.split(path); | |
695 if (dart.notNull(this.isSeparator(path[dartx.codeUnitAt](dart.notNull(path [dartx.length]) - 1)))) segments[dartx.add](''); | |
696 return core.Uri.new({pathSegments: segments}); | |
697 } | |
698 }; | |
699 dart.setSignature(src__internal_style.InternalStyle, { | |
700 methods: () => ({ | |
701 getRoot: [core.String, [core.String]], | |
702 relativePathToUri: [core.Uri, [core.String]] | |
703 }) | |
704 }); | |
705 src__style__posix.PosixStyle = class PosixStyle extends src__internal_style.In ternalStyle { | |
706 PosixStyle() { | |
707 this.separatorPattern = core.RegExp.new('/'); | |
708 this.needsSeparatorPattern = core.RegExp.new('[^/]$'); | |
709 this.rootPattern = core.RegExp.new('^/'); | |
710 this.name = 'posix'; | |
711 this.separator = '/'; | |
712 this.separators = dart.const(dart.list(['/'], core.String)); | |
713 this.relativeRootPattern = null; | |
714 } | |
715 containsSeparator(path) { | |
716 return path[dartx.contains]('/'); | |
717 } | |
718 isSeparator(codeUnit) { | |
719 return codeUnit == src__characters.SLASH; | |
720 } | |
721 needsSeparator(path) { | |
722 return dart.notNull(path[dartx.isNotEmpty]) && !dart.notNull(this.isSepara tor(path[dartx.codeUnitAt](dart.notNull(path[dartx.length]) - 1))); | |
723 } | |
724 rootLength(path) { | |
725 if (dart.notNull(path[dartx.isNotEmpty]) && dart.notNull(this.isSeparator( path[dartx.codeUnitAt](0)))) return 1; | |
726 return 0; | |
727 } | |
728 isRootRelative(path) { | |
729 return false; | |
730 } | |
731 getRelativeRoot(path) { | |
732 return null; | |
733 } | |
734 pathFromUri(uri) { | |
735 if (uri.scheme == '' || uri.scheme == 'file') { | |
736 return core.Uri.decodeComponent(uri.path); | |
737 } | |
738 dart.throw(new core.ArgumentError(`Uri ${uri} must have scheme 'file:'.`)) ; | |
739 } | |
740 absolutePathToUri(path) { | |
741 let parsed = src__parsed_path.ParsedPath.parse(path, this); | |
742 if (dart.notNull(parsed.parts[dartx.isEmpty])) { | |
743 parsed.parts[dartx.addAll](dart.list(["", ""], core.String)); | |
744 } else if (dart.notNull(parsed.hasTrailingSeparator)) { | |
745 parsed.parts[dartx.add](""); | |
746 } | |
747 return core.Uri.new({scheme: 'file', pathSegments: parsed.parts}); | |
748 } | |
749 }; | |
750 dart.setSignature(src__style__posix.PosixStyle, { | |
751 constructors: () => ({PosixStyle: [src__style__posix.PosixStyle, []]}), | |
752 methods: () => ({ | |
753 containsSeparator: [core.bool, [core.String]], | |
754 isSeparator: [core.bool, [core.int]], | |
755 needsSeparator: [core.bool, [core.String]], | |
756 rootLength: [core.int, [core.String]], | |
757 isRootRelative: [core.bool, [core.String]], | |
758 getRelativeRoot: [core.String, [core.String]], | |
759 pathFromUri: [core.String, [core.Uri]], | |
760 absolutePathToUri: [core.Uri, [core.String]] | |
761 }) | |
762 }); | |
763 src__style__url.UrlStyle = class UrlStyle extends src__internal_style.Internal Style { | |
764 UrlStyle() { | |
765 this.separatorPattern = core.RegExp.new('/'); | |
766 this.needsSeparatorPattern = core.RegExp.new("(^[a-zA-Z][-+.a-zA-Z\\d]*:// |[^/])$"); | |
767 this.rootPattern = core.RegExp.new("[a-zA-Z][-+.a-zA-Z\\d]*://[^/]*"); | |
768 this.relativeRootPattern = core.RegExp.new("^/"); | |
769 this.name = 'url'; | |
770 this.separator = '/'; | |
771 this.separators = dart.const(dart.list(['/'], core.String)); | |
772 } | |
773 containsSeparator(path) { | |
774 return path[dartx.contains]('/'); | |
775 } | |
776 isSeparator(codeUnit) { | |
777 return codeUnit == src__characters.SLASH; | |
778 } | |
779 needsSeparator(path) { | |
780 if (dart.notNull(path[dartx.isEmpty])) return false; | |
781 if (!dart.notNull(this.isSeparator(path[dartx.codeUnitAt](dart.notNull(pat h[dartx.length]) - 1)))) return true; | |
782 return dart.notNull(path[dartx.endsWith]("://")) && this.rootLength(path) == path[dartx.length]; | |
783 } | |
784 rootLength(path) { | |
785 if (dart.notNull(path[dartx.isEmpty])) return 0; | |
786 if (dart.notNull(this.isSeparator(path[dartx.codeUnitAt](0)))) return 1; | |
787 let index = path[dartx.indexOf]("/"); | |
788 if (dart.notNull(index) > 0 && dart.notNull(path[dartx.startsWith]('://', dart.notNull(index) - 1))) { | |
789 index = path[dartx.indexOf]('/', dart.notNull(index) + 2); | |
790 if (dart.notNull(index) > 0) return index; | |
791 return path[dartx.length]; | |
792 } | |
793 return 0; | |
794 } | |
795 isRootRelative(path) { | |
796 return dart.notNull(path[dartx.isNotEmpty]) && dart.notNull(this.isSeparat or(path[dartx.codeUnitAt](0))); | |
797 } | |
798 getRelativeRoot(path) { | |
799 return dart.notNull(this.isRootRelative(path)) ? '/' : null; | |
800 } | |
801 pathFromUri(uri) { | |
802 return dart.toString(uri); | |
803 } | |
804 relativePathToUri(path) { | |
805 return core.Uri.parse(path); | |
806 } | |
807 absolutePathToUri(path) { | |
808 return core.Uri.parse(path); | |
809 } | |
810 }; | |
811 dart.setSignature(src__style__url.UrlStyle, { | |
812 constructors: () => ({UrlStyle: [src__style__url.UrlStyle, []]}), | |
813 methods: () => ({ | |
814 containsSeparator: [core.bool, [core.String]], | |
815 isSeparator: [core.bool, [core.int]], | |
816 needsSeparator: [core.bool, [core.String]], | |
817 rootLength: [core.int, [core.String]], | |
818 isRootRelative: [core.bool, [core.String]], | |
819 getRelativeRoot: [core.String, [core.String]], | |
820 pathFromUri: [core.String, [core.Uri]], | |
821 absolutePathToUri: [core.Uri, [core.String]] | |
822 }) | |
823 }); | |
824 src__style__windows.WindowsStyle = class WindowsStyle extends src__internal_st yle.InternalStyle { | |
825 WindowsStyle() { | |
826 this.separatorPattern = core.RegExp.new('[/\\\\]'); | |
827 this.needsSeparatorPattern = core.RegExp.new('[^/\\\\]$'); | |
828 this.rootPattern = core.RegExp.new('^(\\\\\\\\[^\\\\]+\\\\[^\\\\/]+|[a-zA- Z]:[/\\\\])'); | |
829 this.relativeRootPattern = core.RegExp.new("^[/\\\\](?![/\\\\])"); | |
830 this.name = 'windows'; | |
831 this.separator = '\\'; | |
832 this.separators = dart.const(dart.list(['/', '\\'], core.String)); | |
833 } | |
834 containsSeparator(path) { | |
835 return path[dartx.contains]('/'); | |
836 } | |
837 isSeparator(codeUnit) { | |
838 return codeUnit == src__characters.SLASH || codeUnit == src__characters.BA CKSLASH; | |
839 } | |
840 needsSeparator(path) { | |
841 if (dart.notNull(path[dartx.isEmpty])) return false; | |
842 return !dart.notNull(this.isSeparator(path[dartx.codeUnitAt](dart.notNull( path[dartx.length]) - 1))); | |
843 } | |
844 rootLength(path) { | |
845 if (dart.notNull(path[dartx.isEmpty])) return 0; | |
846 if (path[dartx.codeUnitAt](0) == src__characters.SLASH) return 1; | |
847 if (path[dartx.codeUnitAt](0) == src__characters.BACKSLASH) { | |
848 if (dart.notNull(path[dartx.length]) < 2 || path[dartx.codeUnitAt](1) != src__characters.BACKSLASH) return 1; | |
849 let index = path[dartx.indexOf]('\\', 2); | |
850 if (dart.notNull(index) > 0) { | |
851 index = path[dartx.indexOf]('\\', dart.notNull(index) + 1); | |
852 if (dart.notNull(index) > 0) return index; | |
853 } | |
854 return path[dartx.length]; | |
855 } | |
856 if (dart.notNull(path[dartx.length]) < 3) return 0; | |
857 if (!dart.notNull(src__utils.isAlphabetic(path[dartx.codeUnitAt](0)))) ret urn 0; | |
858 if (path[dartx.codeUnitAt](1) != src__characters.COLON) return 0; | |
859 if (!dart.notNull(this.isSeparator(path[dartx.codeUnitAt](2)))) return 0; | |
860 return 3; | |
861 } | |
862 isRootRelative(path) { | |
863 return this.rootLength(path) == 1; | |
864 } | |
865 getRelativeRoot(path) { | |
866 let length = this.rootLength(path); | |
867 if (length == 1) return path[dartx.get](0); | |
868 return null; | |
869 } | |
870 pathFromUri(uri) { | |
871 if (uri.scheme != '' && uri.scheme != 'file') { | |
872 dart.throw(new core.ArgumentError(`Uri ${uri} must have scheme 'file:'.` )); | |
873 } | |
874 let path = uri.path; | |
875 if (uri.host == '') { | |
876 if (dart.notNull(path[dartx.startsWith]('/'))) path = path[dartx.replace First]("/", ""); | |
877 } else { | |
878 path = `\\\\${uri.host}${path}`; | |
879 } | |
880 return core.Uri.decodeComponent(path[dartx.replaceAll]("/", "\\")); | |
881 } | |
882 absolutePathToUri(path) { | |
883 let parsed = src__parsed_path.ParsedPath.parse(path, this); | |
884 if (dart.notNull(parsed.root[dartx.startsWith]('\\\\'))) { | |
885 let rootParts = parsed.root[dartx.split]('\\')[dartx.where](dart.fn(part => part != '', core.bool, [core.String])); | |
886 parsed.parts[dartx.insert](0, rootParts[dartx.last]); | |
887 if (dart.notNull(parsed.hasTrailingSeparator)) { | |
888 parsed.parts[dartx.add](""); | |
889 } | |
890 return core.Uri.new({scheme: 'file', host: rootParts[dartx.first], pathS egments: parsed.parts}); | |
891 } else { | |
892 if (parsed.parts[dartx.length] == 0 || dart.notNull(parsed.hasTrailingSe parator)) { | |
893 parsed.parts[dartx.add](""); | |
894 } | |
895 parsed.parts[dartx.insert](0, parsed.root[dartx.replaceAll]("/", "")[dar tx.replaceAll]("\\", "")); | |
896 return core.Uri.new({scheme: 'file', pathSegments: parsed.parts}); | |
897 } | |
898 } | |
899 }; | |
900 dart.setSignature(src__style__windows.WindowsStyle, { | |
901 constructors: () => ({WindowsStyle: [src__style__windows.WindowsStyle, []]}) , | |
902 methods: () => ({ | |
903 containsSeparator: [core.bool, [core.String]], | |
904 isSeparator: [core.bool, [core.int]], | |
905 needsSeparator: [core.bool, [core.String]], | |
906 rootLength: [core.int, [core.String]], | |
907 isRootRelative: [core.bool, [core.String]], | |
908 getRelativeRoot: [core.String, [core.String]], | |
909 pathFromUri: [core.String, [core.Uri]], | |
910 absolutePathToUri: [core.Uri, [core.String]] | |
911 }) | |
912 }); | |
913 src__utils.isAlphabetic = function(char) { | |
914 return dart.notNull(char) >= dart.notNull(src__characters.UPPER_A) && dart.n otNull(char) <= dart.notNull(src__characters.UPPER_Z) || dart.notNull(char) >= d art.notNull(src__characters.LOWER_A) && dart.notNull(char) <= dart.notNull(src__ characters.LOWER_Z); | |
915 }; | |
916 dart.fn(src__utils.isAlphabetic, core.bool, [core.int]); | |
917 src__utils.isNumeric = function(char) { | |
918 return dart.notNull(char) >= dart.notNull(src__characters.ZERO) && dart.notN ull(char) <= dart.notNull(src__characters.NINE); | |
919 }; | |
920 dart.fn(src__utils.isNumeric, core.bool, [core.int]); | |
921 src__characters.PLUS = 43; | |
922 src__characters.MINUS = 45; | |
923 src__characters.PERIOD = 46; | |
924 src__characters.SLASH = 47; | |
925 src__characters.ZERO = 48; | |
926 src__characters.NINE = 57; | |
927 src__characters.COLON = 58; | |
928 src__characters.UPPER_A = 65; | |
929 src__characters.UPPER_Z = 90; | |
930 src__characters.LOWER_A = 97; | |
931 src__characters.LOWER_Z = 122; | |
932 src__characters.BACKSLASH = 92; | |
933 const _splitExtension = Symbol('_splitExtension'); | |
934 src__parsed_path.ParsedPath = class ParsedPath extends core.Object { | |
935 get extension() { | |
936 return this[_splitExtension]()[dartx.get](1); | |
937 } | |
938 get isAbsolute() { | |
939 return this.root != null; | |
940 } | |
941 static parse(path, style) { | |
942 let root = style.getRoot(path); | |
943 let isRootRelative = style.isRootRelative(path); | |
944 if (root != null) path = path[dartx.substring](root[dartx.length]); | |
945 let parts = dart.list([], core.String); | |
946 let separators = dart.list([], core.String); | |
947 let start = 0; | |
948 if (dart.notNull(path[dartx.isNotEmpty]) && dart.notNull(style.isSeparator (path[dartx.codeUnitAt](0)))) { | |
949 separators[dartx.add](path[dartx.get](0)); | |
950 start = 1; | |
951 } else { | |
952 separators[dartx.add](''); | |
953 } | |
954 for (let i = start; i < dart.notNull(path[dartx.length]); i++) { | |
955 if (dart.notNull(style.isSeparator(path[dartx.codeUnitAt](i)))) { | |
956 parts[dartx.add](path[dartx.substring](start, i)); | |
957 separators[dartx.add](path[dartx.get](i)); | |
958 start = i + 1; | |
959 } | |
960 } | |
961 if (start < dart.notNull(path[dartx.length])) { | |
962 parts[dartx.add](path[dartx.substring](start)); | |
963 separators[dartx.add](''); | |
964 } | |
965 return new src__parsed_path.ParsedPath._(style, root, isRootRelative, part s, separators); | |
966 } | |
967 _(style, root, isRootRelative, parts, separators) { | |
968 this.style = style; | |
969 this.root = root; | |
970 this.isRootRelative = isRootRelative; | |
971 this.parts = parts; | |
972 this.separators = separators; | |
973 } | |
974 get basename() { | |
975 let copy = this.clone(); | |
976 copy.removeTrailingSeparators(); | |
977 if (dart.notNull(copy.parts[dartx.isEmpty])) return this.root == null ? '' : this.root; | |
978 return copy.parts[dartx.last]; | |
979 } | |
980 get basenameWithoutExtension() { | |
981 return this[_splitExtension]()[dartx.get](0); | |
982 } | |
983 get hasTrailingSeparator() { | |
984 return !dart.notNull(this.parts[dartx.isEmpty]) && (this.parts[dartx.last] == '' || this.separators[dartx.last] != ''); | |
985 } | |
986 removeTrailingSeparators() { | |
987 while (!dart.notNull(this.parts[dartx.isEmpty]) && this.parts[dartx.last] == '') { | |
988 this.parts[dartx.removeLast](); | |
989 this.separators[dartx.removeLast](); | |
990 } | |
991 if (dart.notNull(this.separators[dartx.length]) > 0) this.separators[dartx .set](dart.notNull(this.separators[dartx.length]) - 1, ''); | |
992 } | |
993 normalize() { | |
994 let leadingDoubles = 0; | |
995 let newParts = dart.list([], core.String); | |
996 for (let part of this.parts) { | |
997 if (part == '.' || part == '') { | |
998 } else if (part == '..') { | |
999 if (dart.notNull(newParts[dartx.length]) > 0) { | |
1000 newParts[dartx.removeLast](); | |
1001 } else { | |
1002 leadingDoubles++; | |
1003 } | |
1004 } else { | |
1005 newParts[dartx.add](part); | |
1006 } | |
1007 } | |
1008 if (!dart.notNull(this.isAbsolute)) { | |
1009 newParts[dartx.insertAll](0, core.List$(core.String).filled(leadingDoubl es, '..')); | |
1010 } | |
1011 if (newParts[dartx.length] == 0 && !dart.notNull(this.isAbsolute)) { | |
1012 newParts[dartx.add]('.'); | |
1013 } | |
1014 let newSeparators = core.List$(core.String).generate(newParts[dartx.length ], dart.fn(_ => this.style.separator, core.String, [core.int]), {growable: true} ); | |
1015 newSeparators[dartx.insert](0, dart.notNull(this.isAbsolute) && dart.notNu ll(newParts[dartx.length]) > 0 && dart.notNull(this.style.needsSeparator(this.ro ot)) ? this.style.separator : ''); | |
1016 this.parts = newParts; | |
1017 this.separators = newSeparators; | |
1018 if (this.root != null && dart.equals(this.style, src__style.Style.windows) ) { | |
1019 this.root = this.root[dartx.replaceAll]('/', '\\'); | |
1020 } | |
1021 this.removeTrailingSeparators(); | |
1022 } | |
1023 toString() { | |
1024 let builder = new core.StringBuffer(); | |
1025 if (this.root != null) builder.write(this.root); | |
1026 for (let i = 0; i < dart.notNull(this.parts[dartx.length]); i++) { | |
1027 builder.write(this.separators[dartx.get](i)); | |
1028 builder.write(this.parts[dartx.get](i)); | |
1029 } | |
1030 builder.write(this.separators[dartx.last]); | |
1031 return builder.toString(); | |
1032 } | |
1033 [_splitExtension]() { | |
1034 let file = this.parts[dartx.lastWhere](dart.fn(p => p != '', core.bool, [c ore.String]), {orElse: dart.fn(() => null, core.String, [])}); | |
1035 if (file == null) return dart.list(['', ''], core.String); | |
1036 if (file == '..') return dart.list(['..', ''], core.String); | |
1037 let lastDot = file[dartx.lastIndexOf]('.'); | |
1038 if (dart.notNull(lastDot) <= 0) return dart.list([file, ''], core.String); | |
1039 return dart.list([file[dartx.substring](0, lastDot), file[dartx.substring] (lastDot)], core.String); | |
1040 } | |
1041 clone() { | |
1042 return new src__parsed_path.ParsedPath._(this.style, this.root, this.isRoo tRelative, core.List$(core.String).from(this.parts), core.List$(core.String).fro m(this.separators)); | |
1043 } | |
1044 }; | |
1045 dart.defineNamedConstructor(src__parsed_path.ParsedPath, '_'); | |
1046 dart.setSignature(src__parsed_path.ParsedPath, { | |
1047 constructors: () => ({ | |
1048 parse: [src__parsed_path.ParsedPath, [core.String, src__internal_style.Int ernalStyle]], | |
1049 _: [src__parsed_path.ParsedPath, [src__internal_style.InternalStyle, core. String, core.bool, core.List$(core.String), core.List$(core.String)]] | |
1050 }), | |
1051 methods: () => ({ | |
1052 removeTrailingSeparators: [dart.void, []], | |
1053 normalize: [dart.void, []], | |
1054 [_splitExtension]: [core.List$(core.String), []], | |
1055 clone: [src__parsed_path.ParsedPath, []] | |
1056 }) | |
1057 }); | |
1058 // Exports: | |
1059 exports.path = path$; | |
1060 exports.src__context = src__context; | |
1061 exports.src__style = src__style; | |
1062 exports.src__style__posix = src__style__posix; | |
1063 exports.src__style__url = src__style__url; | |
1064 exports.src__style__windows = src__style__windows; | |
1065 exports.src__utils = src__utils; | |
1066 exports.src__characters = src__characters; | |
1067 exports.src__parsed_path = src__parsed_path; | |
1068 exports.src__path_exception = src__path_exception; | |
1069 exports.src__internal_style = src__internal_style; | |
1070 }); | |
OLD | NEW |