| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 /// | 105 /// |
| 106 /// path.join('path/', 'to', 'foo'); // -> 'path/to/foo | 106 /// path.join('path/', 'to', 'foo'); // -> 'path/to/foo |
| 107 /// | 107 /// |
| 108 /// If a part is an absolute path, then anything before that will be ignored: | 108 /// If a part is an absolute path, then anything before that will be ignored: |
| 109 /// | 109 /// |
| 110 /// path.join('path', '/to', 'foo'); // -> '/to/foo' | 110 /// path.join('path', '/to', 'foo'); // -> '/to/foo' |
| 111 String join(String part1, [String part2, String part3, String part4, | 111 String join(String part1, [String part2, String part3, String part4, |
| 112 String part5, String part6, String part7, String part8]) => | 112 String part5, String part6, String part7, String part8]) => |
| 113 _builder.join(part1, part2, part3, part4, part5, part6, part7, part8); | 113 _builder.join(part1, part2, part3, part4, part5, part6, part7, part8); |
| 114 | 114 |
| 115 /// Joins the given path parts into a single path using the current platform's |
| 116 /// [separator]. Example: |
| 117 /// |
| 118 /// path.joinAll(['path', 'to', 'foo']); // -> 'path/to/foo' |
| 119 /// |
| 120 /// If any part ends in a path separator, then a redundant separator will not |
| 121 /// be added: |
| 122 /// |
| 123 /// path.joinAll(['path/', 'to', 'foo']); // -> 'path/to/foo |
| 124 /// |
| 125 /// If a part is an absolute path, then anything before that will be ignored: |
| 126 /// |
| 127 /// path.joinAll(['path', '/to', 'foo']); // -> '/to/foo' |
| 128 /// |
| 129 /// For a fixed number of parts, [join] is usually terser. |
| 130 String joinAll(Iterable<String> parts) => _builder.joinAll(parts); |
| 131 |
| 115 // TODO(nweiz): add a UNC example for Windows once issue 7323 is fixed. | 132 // TODO(nweiz): add a UNC example for Windows once issue 7323 is fixed. |
| 116 /// Splits [path] into its components using the current platform's [separator]. | 133 /// Splits [path] into its components using the current platform's [separator]. |
| 117 /// | 134 /// |
| 118 /// path.split('path/to/foo'); // -> ['path', 'to', 'foo'] | 135 /// path.split('path/to/foo'); // -> ['path', 'to', 'foo'] |
| 119 /// | 136 /// |
| 120 /// The path will *not* be normalized before splitting. | 137 /// The path will *not* be normalized before splitting. |
| 121 /// | 138 /// |
| 122 /// path.split('path/../foo'); // -> ['path', '..', 'foo'] | 139 /// path.split('path/../foo'); // -> ['path', '..', 'foo'] |
| 123 /// | 140 /// |
| 124 /// If [path] is absolute, the root directory will be the first element in the | 141 /// If [path] is absolute, the root directory will be the first element in the |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 /// be added: | 331 /// be added: |
| 315 /// | 332 /// |
| 316 /// builder.join('path/', 'to', 'foo'); // -> 'path/to/foo | 333 /// builder.join('path/', 'to', 'foo'); // -> 'path/to/foo |
| 317 /// | 334 /// |
| 318 /// If a part is an absolute path, then anything before that will be ignored: | 335 /// If a part is an absolute path, then anything before that will be ignored: |
| 319 /// | 336 /// |
| 320 /// builder.join('path', '/to', 'foo'); // -> '/to/foo' | 337 /// builder.join('path', '/to', 'foo'); // -> '/to/foo' |
| 321 /// | 338 /// |
| 322 String join(String part1, [String part2, String part3, String part4, | 339 String join(String part1, [String part2, String part3, String part4, |
| 323 String part5, String part6, String part7, String part8]) { | 340 String part5, String part6, String part7, String part8]) { |
| 341 var parts = [part1, part2, part3, part4, part5, part6, part7, part8]; |
| 342 _validateArgList("join", parts); |
| 343 return joinAll(parts.where((part) => part != null)); |
| 344 } |
| 345 |
| 346 /// Joins the given path parts into a single path. Example: |
| 347 /// |
| 348 /// builder.joinAll(['path', 'to', 'foo']); // -> 'path/to/foo' |
| 349 /// |
| 350 /// If any part ends in a path separator, then a redundant separator will not |
| 351 /// be added: |
| 352 /// |
| 353 /// builder.joinAll(['path/', 'to', 'foo']); // -> 'path/to/foo |
| 354 /// |
| 355 /// If a part is an absolute path, then anything before that will be ignored: |
| 356 /// |
| 357 /// builder.joinAll(['path', '/to', 'foo']); // -> '/to/foo' |
| 358 /// |
| 359 /// For a fixed number of parts, [join] is usually terser. |
| 360 String joinAll(Iterable<String> parts) { |
| 324 var buffer = new StringBuffer(); | 361 var buffer = new StringBuffer(); |
| 325 var needsSeparator = false; | 362 var needsSeparator = false; |
| 326 | 363 |
| 327 var parts = [part1, part2, part3, part4, part5, part6, part7, part8]; | |
| 328 _validateArgList("join", parts); | |
| 329 | |
| 330 for (var part in parts) { | 364 for (var part in parts) { |
| 331 if (part == null) continue; | |
| 332 | |
| 333 if (this.isAbsolute(part)) { | 365 if (this.isAbsolute(part)) { |
| 334 // An absolute path discards everything before it. | 366 // An absolute path discards everything before it. |
| 335 buffer.clear(); | 367 buffer.clear(); |
| 336 buffer.add(part); | 368 buffer.add(part); |
| 337 } else { | 369 } else { |
| 338 if (part.length > 0 && part[0].contains(style.separatorPattern)) { | 370 if (part.length > 0 && part[0].contains(style.separatorPattern)) { |
| 339 // The part starts with a separator, so we don't need to add one. | 371 // The part starts with a separator, so we don't need to add one. |
| 340 } else if (needsSeparator) { | 372 } else if (needsSeparator) { |
| 341 buffer.add(separator); | 373 buffer.add(separator); |
| 342 } | 374 } |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 // If there is no dot, or it's the first character, like '.bashrc', it | 724 // If there is no dot, or it's the first character, like '.bashrc', it |
| 693 // doesn't count. | 725 // doesn't count. |
| 694 if (lastDot <= 0) return [file, '']; | 726 if (lastDot <= 0) return [file, '']; |
| 695 | 727 |
| 696 return [file.substring(0, lastDot), file.substring(lastDot)]; | 728 return [file.substring(0, lastDot), file.substring(lastDot)]; |
| 697 } | 729 } |
| 698 | 730 |
| 699 _ParsedPath clone() => new _ParsedPath( | 731 _ParsedPath clone() => new _ParsedPath( |
| 700 style, root, new List.from(parts), new List.from(separators)); | 732 style, root, new List.from(parts), new List.from(separators)); |
| 701 } | 733 } |
| OLD | NEW |