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

Side by Side Diff: runtime/bin/path_impl.dart

Issue 11096026: Revert "Improving relative path support." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 months 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 | tests/standalone/io/path_test.dart » ('j') | no next file with comments »
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 class _Path implements Path { 5 class _Path implements Path {
6 final String _path; 6 final String _path;
7 7
8 _Path(String source) : _path = source; 8 _Path(String source) : _path = source;
9 _Path.fromNative(String source) : _path = _clean(source); 9 _Path.fromNative(String source) : _path = _clean(source);
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // Throws an exception if no such path exists, or the case is not 42 // Throws an exception if no such path exists, or the case is not
43 // implemented yet. 43 // implemented yet.
44 if (base.isAbsolute && _path.startsWith(base._path)) { 44 if (base.isAbsolute && _path.startsWith(base._path)) {
45 if (_path == base._path) return new Path('.'); 45 if (_path == base._path) return new Path('.');
46 if (base.hasTrailingSeparator) { 46 if (base.hasTrailingSeparator) {
47 return new Path(_path.substring(base._path.length)); 47 return new Path(_path.substring(base._path.length));
48 } 48 }
49 if (_path[base._path.length] == '/') { 49 if (_path[base._path.length] == '/') {
50 return new Path(_path.substring(base._path.length + 1)); 50 return new Path(_path.substring(base._path.length + 1));
51 } 51 }
52 } else if (base.isAbsolute && isAbsolute) {
53 List<String> baseSegments = base.canonicalize().segments();
54 List<String> pathSegments = canonicalize().segments();
55 int common = 0;
56 int length = min(pathSegments.length, baseSegments.length);
57 while (common < length && pathSegments[common] == baseSegments[common]) {
58 common++;
59 }
60 final sb = new StringBuffer();
61
62 for (int i = common + 1; i < baseSegments.length; i++) {
63 sb.add('../');
64 }
65 if (base.hasTrailingSeparator) {
66 sb.add('../');
67 }
68 for (int i = common; i < pathSegments.length - 1; i++) {
69 sb.add('${pathSegments[i]}/');
70 }
71 sb.add('${pathSegments.last()}');
72 if (_path.hasTrailingSeparator) {
73 sb.add('/');
74 }
75 return new Path(sb.toString());
76 } 52 }
77 throw new NotImplementedException( 53 throw new NotImplementedException(
78 "Unimplemented case of Path.relativeTo(base):\n" 54 "Unimplemented case of Path.relativeTo(base):\n"
79 " Only absolute paths are handled at present.\n" 55 " Only absolute paths with strict containment are handled at present.\n"
80 " Arguments: $_path.relativeTo($base)"); 56 " Arguments: $_path.relativeTo($base)");
81 } 57 }
82 58
83 Path join(Path further) { 59 Path join(Path further) {
84 if (further.isAbsolute) { 60 if (further.isAbsolute) {
85 throw new ArgumentError( 61 throw new ArgumentError(
86 "Path.join called with absolute Path as argument."); 62 "Path.join called with absolute Path as argument.");
87 } 63 }
88 if (isEmpty) { 64 if (isEmpty) {
89 return further.canonicalize(); 65 return further.canonicalize();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 if (pos < 0) return new Path(''); 210 if (pos < 0) return new Path('');
235 while (pos > 0 && _path[pos - 1] == '/') --pos; 211 while (pos > 0 && _path[pos - 1] == '/') --pos;
236 return new Path((pos > 0) ? _path.substring(0, pos) : '/'); 212 return new Path((pos > 0) ? _path.substring(0, pos) : '/');
237 } 213 }
238 214
239 String get filename { 215 String get filename {
240 int pos = _path.lastIndexOf('/'); 216 int pos = _path.lastIndexOf('/');
241 return _path.substring(pos + 1); 217 return _path.substring(pos + 1);
242 } 218 }
243 } 219 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/path_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698