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

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

Issue 11189125: Fix path to only use public interface in the implementation of methods. (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 | no next file » | 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 23 matching lines...) Expand all
34 bool get hasTrailingSeparator => _path.endsWith('/'); 34 bool get hasTrailingSeparator => _path.endsWith('/');
35 35
36 String toString() => _path; 36 String toString() => _path;
37 37
38 Path relativeTo(Path base) { 38 Path relativeTo(Path base) {
39 // Throws exception if an unimplemented or impossible case is reached. 39 // Throws exception if an unimplemented or impossible case is reached.
40 // Returns a path "relative" such that 40 // Returns a path "relative" such that
41 // base.join(relative) == this.canonicalize. 41 // base.join(relative) == this.canonicalize.
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 var basePath = base.toString();
45 if (_path == base._path) return new Path('.'); 45 if (base.isAbsolute && _path.startsWith(basePath)) {
46 if (_path == basePath) return new Path('.');
46 if (base.hasTrailingSeparator) { 47 if (base.hasTrailingSeparator) {
47 return new Path(_path.substring(base._path.length)); 48 return new Path(_path.substring(basePath.length));
48 } 49 }
49 if (_path[base._path.length] == '/') { 50 if (_path[basePath.length] == '/') {
50 return new Path(_path.substring(base._path.length + 1)); 51 return new Path(_path.substring(basePath.length + 1));
51 } 52 }
52 } else if (base.isAbsolute && isAbsolute) { 53 } else if (base.isAbsolute && isAbsolute) {
53 List<String> baseSegments = base.canonicalize().segments(); 54 List<String> baseSegments = base.canonicalize().segments();
54 List<String> pathSegments = canonicalize().segments(); 55 List<String> pathSegments = canonicalize().segments();
55 int common = 0; 56 int common = 0;
56 int length = min(pathSegments.length, baseSegments.length); 57 int length = min(pathSegments.length, baseSegments.length);
57 while (common < length && pathSegments[common] == baseSegments[common]) { 58 while (common < length && pathSegments[common] == baseSegments[common]) {
58 common++; 59 common++;
59 } 60 }
60 final sb = new StringBuffer(); 61 final sb = new StringBuffer();
(...skipping 21 matching lines...) Expand all
82 83
83 Path join(Path further) { 84 Path join(Path further) {
84 if (further.isAbsolute) { 85 if (further.isAbsolute) {
85 throw new ArgumentError( 86 throw new ArgumentError(
86 "Path.join called with absolute Path as argument."); 87 "Path.join called with absolute Path as argument.");
87 } 88 }
88 if (isEmpty) { 89 if (isEmpty) {
89 return further.canonicalize(); 90 return further.canonicalize();
90 } 91 }
91 if (hasTrailingSeparator) { 92 if (hasTrailingSeparator) {
92 return new Path('$_path${further._path}').canonicalize(); 93 return new Path('$_path${further}').canonicalize();
93 } 94 }
94 return new Path('$_path/${further._path}').canonicalize(); 95 return new Path('$_path/${further}').canonicalize();
95 } 96 }
96 97
97 // Note: The URI RFC names for these operations are normalize, resolve, and 98 // Note: The URI RFC names for these operations are normalize, resolve, and
98 // relativize. 99 // relativize.
99 Path canonicalize() { 100 Path canonicalize() {
100 if (isCanonical) return this; 101 if (isCanonical) return this;
101 return makeCanonical(); 102 return makeCanonical();
102 } 103 }
103 104
104 bool get isCanonical { 105 bool get isCanonical {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 if (pos < 0) return new Path(''); 235 if (pos < 0) return new Path('');
235 while (pos > 0 && _path[pos - 1] == '/') --pos; 236 while (pos > 0 && _path[pos - 1] == '/') --pos;
236 return new Path((pos > 0) ? _path.substring(0, pos) : '/'); 237 return new Path((pos > 0) ? _path.substring(0, pos) : '/');
237 } 238 }
238 239
239 String get filename { 240 String get filename {
240 int pos = _path.lastIndexOf('/'); 241 int pos = _path.lastIndexOf('/');
241 return _path.substring(pos + 1); 242 return _path.substring(pos + 1);
242 } 243 }
243 } 244 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698