Index: dart/lib/compiler/implementation/util/uri_extras.dart |
diff --git a/dart/lib/compiler/implementation/util/uri_extras.dart b/dart/lib/compiler/implementation/util/uri_extras.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d5e9a8fdbdd2e7f79962fcc84ae99dd0f6a2e350 |
--- /dev/null |
+++ b/dart/lib/compiler/implementation/util/uri_extras.dart |
@@ -0,0 +1,37 @@ |
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+#library('uri_extras'); |
+ |
+#import('dart:uri'); |
+ |
+String relativize(Uri base, Uri uri) { |
+ if (base.scheme == 'file' && |
+ base.scheme == uri.scheme && |
+ base.userInfo == uri.userInfo && |
+ base.domain == uri.domain && |
+ base.port == uri.port && |
+ uri.query == "" && uri.fragment == "") { |
+ if (uri.path.startsWith(base.path)) { |
+ return uri.path.substring(base.path.length); |
+ } |
+ List<String> uriParts = uri.path.split('/'); |
+ List<String> baseParts = base.path.split('/'); |
+ int common = 0; |
+ int length = Math.min(uriParts.length, baseParts.length); |
+ while (common < length && uriParts[common] == baseParts[common]) { |
+ common++; |
+ } |
+ StringBuffer sb = new StringBuffer(); |
+ for (int i = common + 1; i < baseParts.length; i++) { |
+ sb.add('../'); |
+ } |
+ for (int i = common; i < uriParts.length - 1; i++) { |
+ sb.add('${uriParts[i]}/'); |
+ } |
+ sb.add('${uriParts.last()}'); |
+ return sb.toString(); |
+ } |
+ return uri.toString(); |
+} |