| 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 dart.uri; | 5 library dart.uri; |
| 6 | 6 |
| 7 import 'dart:math'; | 7 import 'dart:math'; |
| 8 import 'dart:utf'; | 8 import 'dart:utf'; |
| 9 | 9 |
| 10 part 'encode_decode.dart'; | 10 part 'encode_decode.dart'; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 static const _COMPONENT_USER_INFO = 2; | 85 static const _COMPONENT_USER_INFO = 2; |
| 86 static const _COMPONENT_DOMAIN = 3; | 86 static const _COMPONENT_DOMAIN = 3; |
| 87 static const _COMPONENT_PORT = 4; | 87 static const _COMPONENT_PORT = 4; |
| 88 static const _COMPONENT_PATH = 5; | 88 static const _COMPONENT_PATH = 5; |
| 89 static const _COMPONENT_QUERY_DATA = 6; | 89 static const _COMPONENT_QUERY_DATA = 6; |
| 90 static const _COMPONENT_FRAGMENT = 7; | 90 static const _COMPONENT_FRAGMENT = 7; |
| 91 | 91 |
| 92 /** | 92 /** |
| 93 * Returns `true` if the URI is absolute. | 93 * Returns `true` if the URI is absolute. |
| 94 */ | 94 */ |
| 95 bool isAbsolute() { | 95 bool get isAbsolute { |
| 96 if ("" == scheme) return false; | 96 if ("" == scheme) return false; |
| 97 if ("" != fragment) return false; | 97 if ("" != fragment) return false; |
| 98 return true; | 98 return true; |
| 99 | 99 |
| 100 /* absolute-URI = scheme ":" hier-part [ "?" query ] | 100 /* absolute-URI = scheme ":" hier-part [ "?" query ] |
| 101 * hier-part = "//" authority path-abempty | 101 * hier-part = "//" authority path-abempty |
| 102 * / path-absolute | 102 * / path-absolute |
| 103 * / path-rootless | 103 * / path-rootless |
| 104 * / path-empty | 104 * / path-empty |
| 105 * | 105 * |
| (...skipping 30 matching lines...) Expand all Loading... |
| 136 String targetPath; | 136 String targetPath; |
| 137 String targetQuery; | 137 String targetQuery; |
| 138 if (reference.scheme != "") { | 138 if (reference.scheme != "") { |
| 139 targetScheme = reference.scheme; | 139 targetScheme = reference.scheme; |
| 140 targetUserInfo = reference.userInfo; | 140 targetUserInfo = reference.userInfo; |
| 141 targetDomain = reference.domain; | 141 targetDomain = reference.domain; |
| 142 targetPort = reference.port; | 142 targetPort = reference.port; |
| 143 targetPath = removeDotSegments(reference.path); | 143 targetPath = removeDotSegments(reference.path); |
| 144 targetQuery = reference.query; | 144 targetQuery = reference.query; |
| 145 } else { | 145 } else { |
| 146 if (reference.hasAuthority()) { | 146 if (reference.hasAuthority) { |
| 147 targetUserInfo = reference.userInfo; | 147 targetUserInfo = reference.userInfo; |
| 148 targetDomain = reference.domain; | 148 targetDomain = reference.domain; |
| 149 targetPort = reference.port; | 149 targetPort = reference.port; |
| 150 targetPath = removeDotSegments(reference.path); | 150 targetPath = removeDotSegments(reference.path); |
| 151 targetQuery = reference.query; | 151 targetQuery = reference.query; |
| 152 } else { | 152 } else { |
| 153 if (reference.path == "") { | 153 if (reference.path == "") { |
| 154 targetPath = this.path; | 154 targetPath = this.path; |
| 155 if (reference.query != "") { | 155 if (reference.query != "") { |
| 156 targetQuery = reference.query; | 156 targetQuery = reference.query; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 173 } | 173 } |
| 174 return new Uri.fromComponents(scheme: targetScheme, | 174 return new Uri.fromComponents(scheme: targetScheme, |
| 175 userInfo: targetUserInfo, | 175 userInfo: targetUserInfo, |
| 176 domain: targetDomain, | 176 domain: targetDomain, |
| 177 port: targetPort, | 177 port: targetPort, |
| 178 path: targetPath, | 178 path: targetPath, |
| 179 query: targetQuery, | 179 query: targetQuery, |
| 180 fragment: reference.fragment); | 180 fragment: reference.fragment); |
| 181 } | 181 } |
| 182 | 182 |
| 183 bool hasAuthority() { | 183 bool get hasAuthority { |
| 184 return (userInfo != "") || (domain != "") || (port != 0); | 184 return (userInfo != "") || (domain != "") || (port != 0); |
| 185 } | 185 } |
| 186 | 186 |
| 187 /** | 187 /** |
| 188 * For http/https schemes returns URI's [origin][] - scheme://domain:port. | 188 * For http/https schemes returns URI's [origin][] - scheme://domain:port. |
| 189 * For all other schemes throws ArgumentError. | 189 * For all other schemes throws ArgumentError. |
| 190 * [origin]: http://www.w3.org/TR/2011/WD-html5-20110405/origin-0.html#origin | 190 * [origin]: http://www.w3.org/TR/2011/WD-html5-20110405/origin-0.html#origin |
| 191 */ | 191 */ |
| 192 String get origin { | 192 String get origin { |
| 193 if (scheme == "") { | 193 if (scheme == "") { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 212 if (port != 0) { | 212 if (port != 0) { |
| 213 sb.add(":"); | 213 sb.add(":"); |
| 214 sb.add(port); | 214 sb.add(port); |
| 215 } | 215 } |
| 216 return sb.toString(); | 216 return sb.toString(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 String toString() { | 219 String toString() { |
| 220 StringBuffer sb = new StringBuffer(); | 220 StringBuffer sb = new StringBuffer(); |
| 221 _addIfNonEmpty(sb, scheme, scheme, ':'); | 221 _addIfNonEmpty(sb, scheme, scheme, ':'); |
| 222 if (hasAuthority() || (scheme == "file")) { | 222 if (hasAuthority || (scheme == "file")) { |
| 223 sb.add("//"); | 223 sb.add("//"); |
| 224 _addIfNonEmpty(sb, userInfo, userInfo, "@"); | 224 _addIfNonEmpty(sb, userInfo, userInfo, "@"); |
| 225 sb.add(domain == null ? "null" : domain); | 225 sb.add(domain == null ? "null" : domain); |
| 226 if (port != 0) { | 226 if (port != 0) { |
| 227 sb.add(":"); | 227 sb.add(":"); |
| 228 sb.add(port.toString()); | 228 sb.add(port.toString()); |
| 229 } | 229 } |
| 230 } | 230 } |
| 231 sb.add(path == null ? "null" : path); | 231 sb.add(path == null ? "null" : path); |
| 232 _addIfNonEmpty(sb, query, "?", query); | 232 _addIfNonEmpty(sb, query, "?", query); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 256 } | 256 } |
| 257 | 257 |
| 258 static void _addIfNonEmpty(StringBuffer sb, String test, | 258 static void _addIfNonEmpty(StringBuffer sb, String test, |
| 259 String first, String second) { | 259 String first, String second) { |
| 260 if ("" != test) { | 260 if ("" != test) { |
| 261 sb.add(first == null ? "null" : first); | 261 sb.add(first == null ? "null" : first); |
| 262 sb.add(second == null ? "null" : second); | 262 sb.add(second == null ? "null" : second); |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 } | 265 } |
| OLD | NEW |