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 /// | 6 /// |
7 /// ## Installing ## | 7 /// ## Installing ## |
8 /// | 8 /// |
9 /// Use [pub][] to install this package. Add the following to your | 9 /// Use [pub][] to install this package. Add the following to your |
10 /// `pubspec.yaml` file. | 10 /// `pubspec.yaml` file. |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 /// If a part is an absolute path, then anything before that will be ignored: | 518 /// If a part is an absolute path, then anything before that will be ignored: |
519 /// | 519 /// |
520 /// builder.joinAll(['path', '/to', 'foo']); // -> '/to/foo' | 520 /// builder.joinAll(['path', '/to', 'foo']); // -> '/to/foo' |
521 /// | 521 /// |
522 /// For a fixed number of parts, [join] is usually terser. | 522 /// For a fixed number of parts, [join] is usually terser. |
523 String joinAll(Iterable<String> parts) { | 523 String joinAll(Iterable<String> parts) { |
524 var buffer = new StringBuffer(); | 524 var buffer = new StringBuffer(); |
525 var needsSeparator = false; | 525 var needsSeparator = false; |
526 var isAbsoluteAndNotRootRelative = false; | 526 var isAbsoluteAndNotRootRelative = false; |
527 | 527 |
528 for (var part in parts) { | 528 for (var part in parts.where((part) => part != '')) { |
529 if (this.isRootRelative(part) && isAbsoluteAndNotRootRelative) { | 529 if (this.isRootRelative(part) && isAbsoluteAndNotRootRelative) { |
530 // If the new part is root-relative, it preserves the previous root but | 530 // If the new part is root-relative, it preserves the previous root but |
531 // replaces the path after it. | 531 // replaces the path after it. |
532 var oldRoot = this.rootPrefix(buffer.toString()); | 532 var oldRoot = this.rootPrefix(buffer.toString()); |
533 buffer.clear(); | 533 buffer.clear(); |
534 buffer.write(oldRoot); | 534 buffer.write(oldRoot); |
535 buffer.write(part); | 535 buffer.write(part); |
536 } else if (this.isAbsolute(part)) { | 536 } else if (this.isAbsolute(part)) { |
537 isAbsoluteAndNotRootRelative = !this.isRootRelative(part); | 537 isAbsoluteAndNotRootRelative = !this.isRootRelative(part); |
538 // An absolute path discards everything before it. | 538 // An absolute path discards everything before it. |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1131 // doesn't count. | 1131 // doesn't count. |
1132 if (lastDot <= 0) return [file, '']; | 1132 if (lastDot <= 0) return [file, '']; |
1133 | 1133 |
1134 return [file.substring(0, lastDot), file.substring(lastDot)]; | 1134 return [file.substring(0, lastDot), file.substring(lastDot)]; |
1135 } | 1135 } |
1136 | 1136 |
1137 _ParsedPath clone() => new _ParsedPath( | 1137 _ParsedPath clone() => new _ParsedPath( |
1138 style, root, isRootRelative, | 1138 style, root, isRootRelative, |
1139 new List.from(parts), new List.from(separators)); | 1139 new List.from(parts), new List.from(separators)); |
1140 } | 1140 } |
OLD | NEW |