| 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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 /// For a fixed number of parts, [join] is usually terser. | 553 /// For a fixed number of parts, [join] is usually terser. |
| 554 String joinAll(Iterable<String> parts) { | 554 String joinAll(Iterable<String> parts) { |
| 555 var buffer = new StringBuffer(); | 555 var buffer = new StringBuffer(); |
| 556 var needsSeparator = false; | 556 var needsSeparator = false; |
| 557 var isAbsoluteAndNotRootRelative = false; | 557 var isAbsoluteAndNotRootRelative = false; |
| 558 | 558 |
| 559 for (var part in parts.where((part) => part != '')) { | 559 for (var part in parts.where((part) => part != '')) { |
| 560 if (this.isRootRelative(part) && isAbsoluteAndNotRootRelative) { | 560 if (this.isRootRelative(part) && isAbsoluteAndNotRootRelative) { |
| 561 // If the new part is root-relative, it preserves the previous root but | 561 // If the new part is root-relative, it preserves the previous root but |
| 562 // replaces the path after it. | 562 // replaces the path after it. |
| 563 var oldRoot = this.rootPrefix(buffer.toString()); | 563 var parsed = _parse(part); |
| 564 parsed.root = this.rootPrefix(buffer.toString()); |
| 565 if (parsed.root.contains(style.needsSeparatorPattern)) { |
| 566 parsed.separators[0] = style.separator; |
| 567 } |
| 564 buffer.clear(); | 568 buffer.clear(); |
| 565 buffer.write(oldRoot); | 569 buffer.write(parsed); |
| 566 buffer.write(part); | |
| 567 } else if (this.isAbsolute(part)) { | 570 } else if (this.isAbsolute(part)) { |
| 568 isAbsoluteAndNotRootRelative = !this.isRootRelative(part); | 571 isAbsoluteAndNotRootRelative = !this.isRootRelative(part); |
| 569 // An absolute path discards everything before it. | 572 // An absolute path discards everything before it. |
| 570 buffer.clear(); | 573 buffer.clear(); |
| 571 buffer.write(part); | 574 buffer.write(part); |
| 572 } else { | 575 } else { |
| 573 if (part.length > 0 && part[0].contains(style.separatorPattern)) { | 576 if (part.length > 0 && part[0].contains(style.separatorPattern)) { |
| 574 // The part starts with a separator, so we don't need to add one. | 577 // The part starts with a separator, so we don't need to add one. |
| 575 } else if (needsSeparator) { | 578 } else if (needsSeparator) { |
| 576 buffer.write(separator); | 579 buffer.write(separator); |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 /// The style for Windows paths. | 979 /// The style for Windows paths. |
| 977 class _WindowsStyle extends Style { | 980 class _WindowsStyle extends Style { |
| 978 _WindowsStyle(); | 981 _WindowsStyle(); |
| 979 | 982 |
| 980 final name = 'windows'; | 983 final name = 'windows'; |
| 981 final separator = '\\'; | 984 final separator = '\\'; |
| 982 final separatorPattern = new RegExp(r'[/\\]'); | 985 final separatorPattern = new RegExp(r'[/\\]'); |
| 983 final needsSeparatorPattern = new RegExp(r'[^/\\]$'); | 986 final needsSeparatorPattern = new RegExp(r'[^/\\]$'); |
| 984 final rootPattern = new RegExp(r'^(\\\\[^\\]+\\[^\\/]+|[a-zA-Z]:[/\\])'); | 987 final rootPattern = new RegExp(r'^(\\\\[^\\]+\\[^\\/]+|[a-zA-Z]:[/\\])'); |
| 985 | 988 |
| 989 // Matches a back or forward slash that's not followed by another back or |
| 990 // forward slash. |
| 991 final relativeRootPattern = new RegExp(r"^[/\\](?![/\\])"); |
| 992 |
| 986 String pathFromUri(Uri uri) { | 993 String pathFromUri(Uri uri) { |
| 987 if (uri.scheme != '' && uri.scheme != 'file') { | 994 if (uri.scheme != '' && uri.scheme != 'file') { |
| 988 throw new ArgumentError("Uri $uri must have scheme 'file:'."); | 995 throw new ArgumentError("Uri $uri must have scheme 'file:'."); |
| 989 } | 996 } |
| 990 | 997 |
| 991 var path = uri.path; | 998 var path = uri.path; |
| 992 if (uri.host == '') { | 999 if (uri.host == '') { |
| 993 // Drive-letter paths look like "file:///C:/path/to/file". The | 1000 // Drive-letter paths look like "file:///C:/path/to/file". The |
| 994 // replaceFirst removes the extra initial slash. | 1001 // replaceFirst removes the extra initial slash. |
| 995 if (path.startsWith('/')) path = path.replaceFirst("/", ""); | 1002 if (path.startsWith('/')) path = path.replaceFirst("/", ""); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 // doesn't count. | 1197 // doesn't count. |
| 1191 if (lastDot <= 0) return [file, '']; | 1198 if (lastDot <= 0) return [file, '']; |
| 1192 | 1199 |
| 1193 return [file.substring(0, lastDot), file.substring(lastDot)]; | 1200 return [file.substring(0, lastDot), file.substring(lastDot)]; |
| 1194 } | 1201 } |
| 1195 | 1202 |
| 1196 _ParsedPath clone() => new _ParsedPath( | 1203 _ParsedPath clone() => new _ParsedPath( |
| 1197 style, root, isRootRelative, | 1204 style, root, isRootRelative, |
| 1198 new List.from(parts), new List.from(separators)); | 1205 new List.from(parts), new List.from(separators)); |
| 1199 } | 1206 } |
| OLD | NEW |