Chromium Code Reviews| 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 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 Loading... | |
| 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 print('common $common blLength: ${baseSegments.length}'); | |
|
Mads Ager (google)
2012/10/09 07:02:57
Please remove debug printing.
blois
2012/10/09 16:47:13
d'oh! Done.
| |
| 61 final sb = new StringBuffer(); | |
| 62 | |
| 63 for (int i = common + 1; i < baseSegments.length; i++) { | |
| 64 sb.add('../'); | |
| 65 } | |
| 66 if (base.hasTrailingSeparator) { | |
| 67 sb.add('../'); | |
| 68 } | |
| 69 for (int i = common; i < pathSegments.length - 1; i++) { | |
| 70 sb.add('${pathSegments[i]}/'); | |
| 71 } | |
| 72 sb.add('${pathSegments.last()}'); | |
| 73 if (_path.hasTrailingSeparator) { | |
| 74 sb.add('/'); | |
| 75 } | |
| 76 return new Path(sb.toString()); | |
| 52 } | 77 } |
| 53 throw new NotImplementedException( | 78 throw new NotImplementedException( |
| 54 "Unimplemented case of Path.relativeTo(base):\n" | 79 "Unimplemented case of Path.relativeTo(base):\n" |
| 55 " Only absolute paths with strict containment are handled at present.\n" | 80 " Only absolute paths are handled at present.\n" |
| 56 " Arguments: $_path.relativeTo($base)"); | 81 " Arguments: $_path.relativeTo($base)"); |
| 57 } | 82 } |
| 58 | 83 |
| 59 Path join(Path further) { | 84 Path join(Path further) { |
| 60 if (further.isAbsolute) { | 85 if (further.isAbsolute) { |
| 61 throw new ArgumentError( | 86 throw new ArgumentError( |
| 62 "Path.join called with absolute Path as argument."); | 87 "Path.join called with absolute Path as argument."); |
| 63 } | 88 } |
| 64 if (isEmpty) { | 89 if (isEmpty) { |
| 65 return further.canonicalize(); | 90 return further.canonicalize(); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 if (pos < 0) return new Path(''); | 235 if (pos < 0) return new Path(''); |
| 211 while (pos > 0 && _path[pos - 1] == '/') --pos; | 236 while (pos > 0 && _path[pos - 1] == '/') --pos; |
| 212 return new Path((pos > 0) ? _path.substring(0, pos) : '/'); | 237 return new Path((pos > 0) ? _path.substring(0, pos) : '/'); |
| 213 } | 238 } |
| 214 | 239 |
| 215 String get filename { | 240 String get filename { |
| 216 int pos = _path.lastIndexOf('/'); | 241 int pos = _path.lastIndexOf('/'); |
| 217 return _path.substring(pos + 1); | 242 return _path.substring(pos + 1); |
| 218 } | 243 } |
| 219 } | 244 } |
| OLD | NEW |