| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 /// | 95 /// |
| 96 /// If a part is an absolute path, then anything before that will be ignored: | 96 /// If a part is an absolute path, then anything before that will be ignored: |
| 97 /// | 97 /// |
| 98 /// path.join('path', '/to', 'foo'); // -> '/to/foo' | 98 /// path.join('path', '/to', 'foo'); // -> '/to/foo' |
| 99 String join(String part1, [String part2, String part3, String part4, | 99 String join(String part1, [String part2, String part3, String part4, |
| 100 String part5, String part6, String part7, String part8]) => | 100 String part5, String part6, String part7, String part8]) => |
| 101 _builder.join(part1, part2, part3, part4, part5, part6, part7, part8); | 101 _builder.join(part1, part2, part3, part4, part5, part6, part7, part8); |
| 102 | 102 |
| 103 // TODO(nweiz): add a UNC example for Windows once issue 7323 is fixed. | 103 // TODO(nweiz): add a UNC example for Windows once issue 7323 is fixed. |
| 104 /// Splits [path] into its components using the current platform's [separator]. | 104 /// Splits [path] into its components using the current platform's [separator]. |
| 105 /// Example: | |
| 106 /// | 105 /// |
| 107 /// path.split('path/to/foo'); // -> ['path', 'to', 'foo'] | 106 /// path.split('path/to/foo'); // -> ['path', 'to', 'foo'] |
| 108 /// | 107 /// |
| 108 /// The path will *not* be normalized before splitting. |
| 109 /// |
| 110 /// path.split('path/../foo'); // -> ['path', '..', 'foo'] |
| 111 /// |
| 109 /// If [path] is absolute, the root directory will be the first element in the | 112 /// If [path] is absolute, the root directory will be the first element in the |
| 110 /// array. Example: | 113 /// array. Example: |
| 111 /// | 114 /// |
| 112 /// // Unix | 115 /// // Unix |
| 113 /// path.split('/path/to/foo'); // -> ['/', 'path', 'to', 'foo'] | 116 /// path.split('/path/to/foo'); // -> ['/', 'path', 'to', 'foo'] |
| 114 /// | 117 /// |
| 115 /// // Windows | 118 /// // Windows |
| 116 /// path.split(r'C:\path\to\foo'); // -> [r'C:\', 'path', 'to', 'foo'] | 119 /// path.split(r'C:\path\to\foo'); // -> [r'C:\', 'path', 'to', 'foo'] |
| 117 List<String> split(String path) => _builder.split(path); | 120 List<String> split(String path) => _builder.split(path); |
| 118 | 121 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 311 |
| 309 return buffer.toString(); | 312 return buffer.toString(); |
| 310 } | 313 } |
| 311 | 314 |
| 312 // TODO(nweiz): add a UNC example for Windows once issue 7323 is fixed. | 315 // TODO(nweiz): add a UNC example for Windows once issue 7323 is fixed. |
| 313 /// Splits [path] into its components using the current platform's | 316 /// Splits [path] into its components using the current platform's |
| 314 /// [separator]. Example: | 317 /// [separator]. Example: |
| 315 /// | 318 /// |
| 316 /// builder.split('path/to/foo'); // -> ['path', 'to', 'foo'] | 319 /// builder.split('path/to/foo'); // -> ['path', 'to', 'foo'] |
| 317 /// | 320 /// |
| 321 /// The path will *not* be normalized before splitting. |
| 322 /// |
| 323 /// builder.split('path/../foo'); // -> ['path', '..', 'foo'] |
| 324 /// |
| 318 /// If [path] is absolute, the root directory will be the first element in the | 325 /// If [path] is absolute, the root directory will be the first element in the |
| 319 /// array. Example: | 326 /// array. Example: |
| 320 /// | 327 /// |
| 321 /// // Unix | 328 /// // Unix |
| 322 /// builder.split('/path/to/foo'); // -> ['/', 'path', 'to', 'foo'] | 329 /// builder.split('/path/to/foo'); // -> ['/', 'path', 'to', 'foo'] |
| 323 /// | 330 /// |
| 324 /// // Windows | 331 /// // Windows |
| 325 /// builder.split(r'C:\path\to\foo'); // -> [r'C:\', 'path', 'to', 'foo'] | 332 /// builder.split(r'C:\path\to\foo'); // -> [r'C:\', 'path', 'to', 'foo'] |
| 326 List<String> split(String path) { | 333 List<String> split(String path) { |
| 327 var parsed = _parse(path); | 334 var parsed = _parse(path); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 | 642 |
| 636 var lastDot = file.lastIndexOf('.'); | 643 var lastDot = file.lastIndexOf('.'); |
| 637 | 644 |
| 638 // If there is no dot, or it's the first character, like '.bashrc', it | 645 // If there is no dot, or it's the first character, like '.bashrc', it |
| 639 // doesn't count. | 646 // doesn't count. |
| 640 if (lastDot <= 0) return [file, '']; | 647 if (lastDot <= 0) return [file, '']; |
| 641 | 648 |
| 642 return [file.substring(0, lastDot), file.substring(lastDot)]; | 649 return [file.substring(0, lastDot), file.substring(lastDot)]; |
| 643 } | 650 } |
| 644 } | 651 } |
| OLD | NEW |