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

Unified Diff: dart/lib/compiler/implementation/util/uri_extras.dart

Issue 10914094: Improve [relativize] for Windows. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 3 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 | « dart/lib/compiler/implementation/dart2js.dart ('k') | dart/pkg/dartdoc/mirrors/dart2js_mirror.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index 9a57d983933c571ded1c9f59620a8adbf6a5f065..ecff80da3c1609c8ab271582ca7e03ec7ac05180 100644
--- a/dart/lib/compiler/implementation/util/uri_extras.dart
+++ b/dart/lib/compiler/implementation/util/uri_extras.dart
@@ -7,23 +7,50 @@
#import('dart:math');
#import('dart:uri');
-String relativize(Uri base, Uri uri) {
- if (base.scheme == 'file' &&
- base.scheme == uri.scheme &&
+String relativize(Uri base, Uri uri, bool isWindows) {
+ if (!base.path.startsWith('/')) {
+ // Also throw an exception if [base] or base.path is null.
+ throw new IllegalArgumentException('Expected absolute path: ${base.path}');
+ }
+ if (!uri.path.startsWith('/')) {
+ // Also throw an exception if [uri] or uri.path is null.
+ throw new IllegalArgumentException('Expected absolute path: ${uri.path}');
+ }
+ bool equalsNCS(String a, String b) {
+ return a.toLowerCase() == b.toLowerCase();
+ }
+
+ String normalize(String path) {
+ if (isWindows) {
+ return path.toLowerCase();
+ } else {
+ return path;
+ }
+ }
+
+ if (equalsNCS(base.scheme, 'file') &&
+ equalsNCS(base.scheme, uri.scheme) &&
base.userInfo == uri.userInfo &&
- base.domain == uri.domain &&
+ equalsNCS(base.domain, uri.domain) &&
base.port == uri.port &&
uri.query == "" && uri.fragment == "") {
- if (uri.path.startsWith(base.path)) {
+ if (normalize(uri.path).startsWith(normalize(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 = min(uriParts.length, baseParts.length);
- while (common < length && uriParts[common] == baseParts[common]) {
+ while (common < length &&
+ normalize(uriParts[common]) == normalize(baseParts[common])) {
common++;
}
+ if (common == 1 || (isWindows && common == 2)) {
+ // The first part will always be an empty string because the
+ // paths are absolute. On Windows, we must also consider drive
+ // letters or hostnames.
+ return uri.path;
+ }
StringBuffer sb = new StringBuffer();
for (int i = common + 1; i < baseParts.length; i++) {
sb.add('../');
« no previous file with comments | « dart/lib/compiler/implementation/dart2js.dart ('k') | dart/pkg/dartdoc/mirrors/dart2js_mirror.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698