OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// A comprehensive, cross-platform path manipulation library. | 5 /// A comprehensive, cross-platform path manipulation library. |
6 library path; | 6 library path; |
7 | 7 |
8 import 'dart:io' as io; | 8 import 'dart:io' as io; |
9 | 9 |
10 /// An internal builder for the current OS so we can provide a straight | 10 /// An internal builder for the current OS so we can provide a straight |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 /// array. Example: | 399 /// array. Example: |
400 /// | 400 /// |
401 /// // Unix | 401 /// // Unix |
402 /// builder.split('/path/to/foo'); // -> ['/', 'path', 'to', 'foo'] | 402 /// builder.split('/path/to/foo'); // -> ['/', 'path', 'to', 'foo'] |
403 /// | 403 /// |
404 /// // Windows | 404 /// // Windows |
405 /// builder.split(r'C:\path\to\foo'); // -> [r'C:\', 'path', 'to', 'foo'] | 405 /// builder.split(r'C:\path\to\foo'); // -> [r'C:\', 'path', 'to', 'foo'] |
406 List<String> split(String path) { | 406 List<String> split(String path) { |
407 var parsed = _parse(path); | 407 var parsed = _parse(path); |
408 // Filter out empty parts that exist due to multiple separators in a row. | 408 // Filter out empty parts that exist due to multiple separators in a row. |
409 parsed.parts = parsed.parts.where((part) => !part.isEmpty).toList(); | 409 parsed.parts = parsed.parts.where((part) => !part.isEmpty) |
| 410 .toList(growable: true); |
410 if (parsed.root != null) parsed.parts.insertRange(0, 1, parsed.root); | 411 if (parsed.root != null) parsed.parts.insertRange(0, 1, parsed.root); |
411 return parsed.parts; | 412 return parsed.parts; |
412 } | 413 } |
413 | 414 |
414 /// Normalizes [path], simplifying it by handling `..`, and `.`, and | 415 /// Normalizes [path], simplifying it by handling `..`, and `.`, and |
415 /// removing redundant path separators whenever possible. | 416 /// removing redundant path separators whenever possible. |
416 /// | 417 /// |
417 /// builder.normalize('path/./to/..//file.text'); // -> 'path/file.txt' | 418 /// builder.normalize('path/./to/..//file.text'); // -> 'path/file.txt' |
418 String normalize(String path) { | 419 String normalize(String path) { |
419 if (path == '') return path; | 420 if (path == '') return path; |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 // If there is no dot, or it's the first character, like '.bashrc', it | 725 // If there is no dot, or it's the first character, like '.bashrc', it |
725 // doesn't count. | 726 // doesn't count. |
726 if (lastDot <= 0) return [file, '']; | 727 if (lastDot <= 0) return [file, '']; |
727 | 728 |
728 return [file.substring(0, lastDot), file.substring(lastDot)]; | 729 return [file.substring(0, lastDot), file.substring(lastDot)]; |
729 } | 730 } |
730 | 731 |
731 _ParsedPath clone() => new _ParsedPath( | 732 _ParsedPath clone() => new _ParsedPath( |
732 style, root, new List.from(parts), new List.from(separators)); | 733 style, root, new List.from(parts), new List.from(separators)); |
733 } | 734 } |
OLD | NEW |