OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 #library('uri_extras'); | |
6 | |
7 #import('dart:uri'); | |
8 | |
9 String relativize(Uri base, Uri uri) { | |
ngeoffray
2012/04/24 14:29:46
Why isn't that method in uri instead?
ahe
2012/04/24 14:55:34
I'm not sure if it belongs there.
| |
10 if (base.scheme == 'file' && | |
11 base.scheme == uri.scheme && | |
12 base.userInfo == uri.userInfo && | |
13 base.domain == uri.domain && | |
14 base.port == uri.port && | |
15 uri.query == "" && uri.fragment == "") { | |
16 if (uri.path.startsWith(base.path)) { | |
17 return uri.path.substring(base.path.length); | |
18 } | |
19 List<String> uriParts = uri.path.split('/'); | |
20 List<String> baseParts = base.path.split('/'); | |
21 int common = 0; | |
22 int length = Math.min(uriParts.length, baseParts.length); | |
23 while (common < length && uriParts[common] == baseParts[common]) { | |
24 common++; | |
25 } | |
26 StringBuffer sb = new StringBuffer(); | |
27 for (int i = common + 1; i < baseParts.length; i++) { | |
28 sb.add('../'); | |
29 } | |
30 for (int i = common; i < uriParts.length - 1; i++) { | |
31 sb.add('${uriParts[i]}/'); | |
32 } | |
33 sb.add('${uriParts.last()}'); | |
34 return sb.toString(); | |
35 } | |
36 return uri.toString(); | |
37 } | |
OLD | NEW |