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

Unified Diff: runtime/bin/path_impl.dart

Issue 10986078: Adding more relative path support. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cleanup tests and fixes based on tests. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/standalone/io/path_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/path_impl.dart
diff --git a/runtime/bin/path_impl.dart b/runtime/bin/path_impl.dart
index 9c7e43825e96a84a26c092c59c7adcfe4f8d816b..de6610c1ba1b495484ca04e88259ca54fd571b30 100644
--- a/runtime/bin/path_impl.dart
+++ b/runtime/bin/path_impl.dart
@@ -49,10 +49,35 @@ class _Path implements Path {
if (_path[base._path.length] == '/') {
return new Path(_path.substring(base._path.length + 1));
}
+ } else if (base.isAbsolute && isAbsolute) {
+ List<String> baseSegments = base.canonicalize().segments();
+ List<String> pathSegments = canonicalize().segments();
+ int common = 0;
+ int length = min(pathSegments.length, baseSegments.length);
+ while (common < length && pathSegments[common] == baseSegments[common]) {
+ common++;
+ }
+ 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.
+ final sb = new StringBuffer();
+
+ for (int i = common + 1; i < baseSegments.length; i++) {
+ sb.add('../');
+ }
+ if (base.hasTrailingSeparator) {
+ sb.add('../');
+ }
+ for (int i = common; i < pathSegments.length - 1; i++) {
+ sb.add('${pathSegments[i]}/');
+ }
+ sb.add('${pathSegments.last()}');
+ if (_path.hasTrailingSeparator) {
+ sb.add('/');
+ }
+ return new Path(sb.toString());
}
throw new NotImplementedException(
"Unimplemented case of Path.relativeTo(base):\n"
- " Only absolute paths with strict containment are handled at present.\n"
+ " Only absolute paths are handled at present.\n"
" Arguments: $_path.relativeTo($base)");
}
« 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