| 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 /** | 7 /** |
| 8 * A parsed URI, inspired by: | 8 * A parsed URI, inspired by: |
| 9 * http://closure-library.googlecode.com/svn/docs/class_goog_Uri.html | 9 * http://closure-library.googlecode.com/svn/docs/class_goog_Uri.html |
| 10 */ | 10 */ |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 static int _parseIntOrZero(String val) { | 37 static int _parseIntOrZero(String val) { |
| 38 if (val !== null && val != '') { | 38 if (val !== null && val != '') { |
| 39 return Math.parseInt(val); | 39 return Math.parseInt(val); |
| 40 } else { | 40 } else { |
| 41 return 0; | 41 return 0; |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 // NOTE: This code was ported from: closure-library/closure/goog/uri/utils.js | 45 // NOTE: This code was ported from: closure-library/closure/goog/uri/utils.js |
| 46 static final RegExp _splitRe = const RegExp( | 46 static final RegExp _splitRe = const RegExp( |
| 47 '^' + | 47 '^' |
| 48 '(?:' + | 48 '(?:' |
| 49 '([^:/?#.]+)' + // scheme - ignore special characters | 49 '([^:/?#.]+)' // scheme - ignore special characters |
| 50 // used by other URL parts such as :, | 50 // used by other URL parts such as :, |
| 51 // ?, /, #, and . | 51 // ?, /, #, and . |
| 52 ':)?' + | 52 ':)?' |
| 53 '(?://' + | 53 '(?://' |
| 54 '(?:([^/?#]*)@)?' + // userInfo | 54 '(?:([^/?#]*)@)?' // userInfo |
| 55 '([\\w\\d\\-\\u0100-\\uffff.%]*)' + | 55 '([\\w\\d\\-\\u0100-\\uffff.%]*)' |
| 56 // domain - restrict to letters, | 56 // domain - restrict to letters, |
| 57 // digits, dashes, dots, percent | 57 // digits, dashes, dots, percent |
| 58 // escapes, and unicode characters. | 58 // escapes, and unicode characters. |
| 59 '(?::([0-9]+))?' + // port | 59 '(?::([0-9]+))?' // port |
| 60 ')?' + | 60 ')?' |
| 61 '([^?#]+)?' + // path | 61 '([^?#]+)?' // path |
| 62 '(?:\\?([^#]*))?' + // query | 62 '(?:\\?([^#]*))?' // query |
| 63 '(?:#(.*))?' + // fragment | 63 '(?:#(.*))?' // fragment |
| 64 '\$'); | 64 '\$'); |
| 65 | 65 |
| 66 static final _COMPONENT_SCHEME = 1; | 66 static final _COMPONENT_SCHEME = 1; |
| 67 static final _COMPONENT_USER_INFO = 2; | 67 static final _COMPONENT_USER_INFO = 2; |
| 68 static final _COMPONENT_DOMAIN = 3; | 68 static final _COMPONENT_DOMAIN = 3; |
| 69 static final _COMPONENT_PORT = 4; | 69 static final _COMPONENT_PORT = 4; |
| 70 static final _COMPONENT_PATH = 5; | 70 static final _COMPONENT_PATH = 5; |
| 71 static final _COMPONENT_QUERY_DATA = 6; | 71 static final _COMPONENT_QUERY_DATA = 6; |
| 72 static final _COMPONENT_FRAGMENT = 7; | 72 static final _COMPONENT_FRAGMENT = 7; |
| 73 | 73 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 String first, String second) { | 185 String first, String second) { |
| 186 if ("" != test) { | 186 if ("" != test) { |
| 187 sb.add(first === null ? "null" : first); | 187 sb.add(first === null ? "null" : first); |
| 188 sb.add(second === null ? "null" : second); | 188 sb.add(second === null ? "null" : second); |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 | 192 |
| 193 String merge(String base, String reference) { | 193 String merge(String base, String reference) { |
| 194 if (base == "") return "/$reference"; | 194 if (base == "") return "/$reference"; |
| 195 return base.substring(0, base.lastIndexOf("/") + 1) + "$reference"; | 195 return "${base.substring(0, base.lastIndexOf('/') + 1)}$reference"; |
| 196 } | 196 } |
| 197 | 197 |
| 198 String removeDotSegments(String path) { | 198 String removeDotSegments(String path) { |
| 199 List<String> output = []; | 199 List<String> output = []; |
| 200 bool appendSlash = false; | 200 bool appendSlash = false; |
| 201 for (String segment in path.split("/")) { | 201 for (String segment in path.split("/")) { |
| 202 appendSlash = false; | 202 appendSlash = false; |
| 203 if (segment == "..") { | 203 if (segment == "..") { |
| 204 if (!output.isEmpty() && | 204 if (!output.isEmpty() && |
| 205 ((output.length != 1) || (output[0] != ""))) output.removeLast(); | 205 ((output.length != 1) || (output[0] != ""))) output.removeLast(); |
| 206 appendSlash = true; | 206 appendSlash = true; |
| 207 } else if ("." == segment) { | 207 } else if ("." == segment) { |
| 208 appendSlash = true; | 208 appendSlash = true; |
| 209 } else { | 209 } else { |
| 210 output.add(segment); | 210 output.add(segment); |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 if (appendSlash) output.add(""); | 213 if (appendSlash) output.add(""); |
| 214 return Strings.join(output, "/"); | 214 return Strings.join(output, "/"); |
| 215 } | 215 } |
| OLD | NEW |