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 part of dart.uri; | |
6 | |
7 String merge(String base, String reference) { | 5 String merge(String base, String reference) { |
8 if (base == "") return "/$reference"; | 6 if (base == "") return "/$reference"; |
9 return "${base.substring(0, base.lastIndexOf("/") + 1)}$reference"; | 7 return "${base.substring(0, base.lastIndexOf("/") + 1)}$reference"; |
10 } | 8 } |
11 | 9 |
12 String removeDotSegments(String path) { | 10 String removeDotSegments(String path) { |
13 List<String> output = []; | 11 List<String> output = []; |
14 bool appendSlash = false; | 12 bool appendSlash = false; |
15 for (String segment in path.split("/")) { | 13 for (String segment in path.split("/")) { |
16 appendSlash = false; | 14 appendSlash = false; |
17 if (segment == "..") { | 15 if (segment == "..") { |
18 if (!output.isEmpty && | 16 if (!output.isEmpty && |
19 ((output.length != 1) || (output[0] != ""))) output.removeLast(); | 17 ((output.length != 1) || (output[0] != ""))) output.removeLast(); |
20 appendSlash = true; | 18 appendSlash = true; |
21 } else if ("." == segment) { | 19 } else if ("." == segment) { |
22 appendSlash = true; | 20 appendSlash = true; |
23 } else { | 21 } else { |
24 output.add(segment); | 22 output.add(segment); |
25 } | 23 } |
26 } | 24 } |
27 if (appendSlash) output.add(""); | 25 if (appendSlash) output.add(""); |
28 return Strings.join(output, "/"); | 26 return Strings.join(output, "/"); |
29 } | 27 } |
OLD | NEW |