Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Side by Side Diff: pkg/path/lib/path.dart

Issue 68503011: Support root-relative paths on Windows. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/path/test/windows_test.dart » ('j') | pkg/path/test/windows_test.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.toString());
Bob Nystrom 2013/11/14 17:05:08 The toString() isn't needed here.
nweiz 2013/11/14 21:10:17 Done.
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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 978
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]:[/\\])');
988 final relativeRootPattern = new RegExp(r"^[/\\](?![/\\])");
Bob Nystrom 2013/11/14 17:05:08 Doc comment for this please. Regexen are opaque.
nweiz 2013/11/14 21:10:17 Done.
985 989
986 String pathFromUri(Uri uri) { 990 String pathFromUri(Uri uri) {
987 if (uri.scheme != '' && uri.scheme != 'file') { 991 if (uri.scheme != '' && uri.scheme != 'file') {
988 throw new ArgumentError("Uri $uri must have scheme 'file:'."); 992 throw new ArgumentError("Uri $uri must have scheme 'file:'.");
989 } 993 }
990 994
991 var path = uri.path; 995 var path = uri.path;
992 if (uri.host == '') { 996 if (uri.host == '') {
993 // Drive-letter paths look like "file:///C:/path/to/file". The 997 // Drive-letter paths look like "file:///C:/path/to/file". The
994 // replaceFirst removes the extra initial slash. 998 // replaceFirst removes the extra initial slash.
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 // doesn't count. 1194 // doesn't count.
1191 if (lastDot <= 0) return [file, '']; 1195 if (lastDot <= 0) return [file, ''];
1192 1196
1193 return [file.substring(0, lastDot), file.substring(lastDot)]; 1197 return [file.substring(0, lastDot), file.substring(lastDot)];
1194 } 1198 }
1195 1199
1196 _ParsedPath clone() => new _ParsedPath( 1200 _ParsedPath clone() => new _ParsedPath(
1197 style, root, isRootRelative, 1201 style, root, isRootRelative,
1198 new List.from(parts), new List.from(separators)); 1202 new List.from(parts), new List.from(separators));
1199 } 1203 }
OLDNEW
« no previous file with comments | « no previous file | pkg/path/test/windows_test.dart » ('j') | pkg/path/test/windows_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698