| 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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 /// array. Example: | 349 /// array. Example: |
| 350 /// | 350 /// |
| 351 /// // Unix | 351 /// // Unix |
| 352 /// builder.split('/path/to/foo'); // -> ['/', 'path', 'to', 'foo'] | 352 /// builder.split('/path/to/foo'); // -> ['/', 'path', 'to', 'foo'] |
| 353 /// | 353 /// |
| 354 /// // Windows | 354 /// // Windows |
| 355 /// builder.split(r'C:\path\to\foo'); // -> [r'C:\', 'path', 'to', 'foo'] | 355 /// builder.split(r'C:\path\to\foo'); // -> [r'C:\', 'path', 'to', 'foo'] |
| 356 List<String> split(String path) { | 356 List<String> split(String path) { |
| 357 var parsed = _parse(path); | 357 var parsed = _parse(path); |
| 358 // Filter out empty parts that exist due to multiple separators in a row. | 358 // Filter out empty parts that exist due to multiple separators in a row. |
| 359 parsed.parts = parsed.parts.filter((part) => part != ''); | 359 parsed.parts = parsed.parts.where((part) => !part.isEmpty).toList(); |
| 360 if (parsed.root != null) parsed.parts.insertRange(0, 1, parsed.root); | 360 if (parsed.root != null) parsed.parts.insertRange(0, 1, parsed.root); |
| 361 return parsed.parts; | 361 return parsed.parts; |
| 362 } | 362 } |
| 363 | 363 |
| 364 /// Normalizes [path], simplifying it by handling `..`, and `.`, and | 364 /// Normalizes [path], simplifying it by handling `..`, and `.`, and |
| 365 /// removing redundant path separators whenever possible. | 365 /// removing redundant path separators whenever possible. |
| 366 /// | 366 /// |
| 367 /// builder.normalize('path/./to/..//file.text'); // -> 'path/file.txt' | 367 /// builder.normalize('path/./to/..//file.text'); // -> 'path/file.txt' |
| 368 String normalize(String path) { | 368 String normalize(String path) { |
| 369 if (path == '') return path; | 369 if (path == '') return path; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 // If there is no dot, or it's the first character, like '.bashrc', it | 672 // If there is no dot, or it's the first character, like '.bashrc', it |
| 673 // doesn't count. | 673 // doesn't count. |
| 674 if (lastDot <= 0) return [file, '']; | 674 if (lastDot <= 0) return [file, '']; |
| 675 | 675 |
| 676 return [file.substring(0, lastDot), file.substring(lastDot)]; | 676 return [file.substring(0, lastDot), file.substring(lastDot)]; |
| 677 } | 677 } |
| 678 | 678 |
| 679 _ParsedPath clone() => new _ParsedPath( | 679 _ParsedPath clone() => new _ParsedPath( |
| 680 style, root, new List.from(parts), new List.from(separators)); | 680 style, root, new List.from(parts), new List.from(separators)); |
| 681 } | 681 } |
| OLD | NEW |