| 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 #library('uri'); | 5 #library('uri'); |
| 6 | 6 |
| 7 #source('helpers.dart'); |
| 8 |
| 7 /** | 9 /** |
| 8 * A parsed URI, inspired by Closure's [URI][] class. Implements [RFC-3986][]. | 10 * A parsed URI, inspired by Closure's [URI][] class. Implements [RFC-3986][]. |
| 9 * [uri]: http://closure-library.googlecode.com/svn/docs/class_goog_Uri.html | 11 * [uri]: http://closure-library.googlecode.com/svn/docs/class_goog_Uri.html |
| 10 * [RFC-3986]: http://tools.ietf.org/html/rfc3986#section-4.3) | 12 * [RFC-3986]: http://tools.ietf.org/html/rfc3986#section-4.3) |
| 11 */ | 13 */ |
| 12 class Uri { | 14 class Uri { |
| 13 final String scheme; | 15 final String scheme; |
| 14 final String userInfo; | 16 final String userInfo; |
| 15 final String domain; | 17 final String domain; |
| 16 final int port; | 18 final int port; |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 183 } |
| 182 | 184 |
| 183 static void _addIfNonEmpty(StringBuffer sb, String test, | 185 static void _addIfNonEmpty(StringBuffer sb, String test, |
| 184 String first, String second) { | 186 String first, String second) { |
| 185 if ("" != test) { | 187 if ("" != test) { |
| 186 sb.add(first === null ? "null" : first); | 188 sb.add(first === null ? "null" : first); |
| 187 sb.add(second === null ? "null" : second); | 189 sb.add(second === null ? "null" : second); |
| 188 } | 190 } |
| 189 } | 191 } |
| 190 } | 192 } |
| 191 | |
| 192 String merge(String base, String reference) { | |
| 193 if (base == "") return "/$reference"; | |
| 194 return "${base.substring(0, base.lastIndexOf("/") + 1)}$reference"; | |
| 195 } | |
| 196 | |
| 197 String removeDotSegments(String path) { | |
| 198 List<String> output = []; | |
| 199 bool appendSlash = false; | |
| 200 for (String segment in path.split("/")) { | |
| 201 appendSlash = false; | |
| 202 if (segment == "..") { | |
| 203 if (!output.isEmpty() && | |
| 204 ((output.length != 1) || (output[0] != ""))) output.removeLast(); | |
| 205 appendSlash = true; | |
| 206 } else if ("." == segment) { | |
| 207 appendSlash = true; | |
| 208 } else { | |
| 209 output.add(segment); | |
| 210 } | |
| 211 } | |
| 212 if (appendSlash) output.add(""); | |
| 213 return Strings.join(output, "/"); | |
| 214 } | |
| OLD | NEW |