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'; |
11 part 'helpers.dart'; | 11 part 'helpers.dart'; |
12 | 12 |
13 /** | 13 /** |
14 * A parsed URI, inspired by Closure's [URI][] class. Implements [RFC-3986][]. | 14 * A parsed URI, inspired by Closure's [URI][] class. Implements [RFC-3986][]. |
15 * [uri]: http://closure-library.googlecode.com/svn/docs/class_goog_Uri.html | 15 * [uri]: http://closure-library.googlecode.com/svn/docs/class_goog_Uri.html |
16 * [RFC-3986]: http://tools.ietf.org/html/rfc3986#section-4.3) | 16 * [RFC-3986]: http://tools.ietf.org/html/rfc3986#section-4.3) |
17 */ | 17 */ |
18 class Uri { | 18 class Uri { |
19 final String scheme; | 19 final String scheme; |
20 final String userInfo; | 20 final String userInfo; |
21 final String domain; | 21 final String domain; |
22 final int port; | 22 final int port; |
23 final String path; | 23 final String path; |
24 final String query; | 24 final String query; |
25 final String fragment; | 25 final String fragment; |
26 | 26 |
| 27 /** |
| 28 * Deprecated. Please use [parse] instead. |
| 29 */ |
| 30 @deprecated |
27 Uri.fromString(String uri) : this._fromMatch(_splitRe.firstMatch(uri)); | 31 Uri.fromString(String uri) : this._fromMatch(_splitRe.firstMatch(uri)); |
28 | 32 |
| 33 static Uri parse(String uri) => new Uri._fromMatch(_splitRe.firstMatch(uri)); |
| 34 |
29 Uri._fromMatch(Match m) : | 35 Uri._fromMatch(Match m) : |
30 this.fromComponents(scheme: _emptyIfNull(m[_COMPONENT_SCHEME]), | 36 this.fromComponents(scheme: _emptyIfNull(m[_COMPONENT_SCHEME]), |
31 userInfo: _emptyIfNull(m[_COMPONENT_USER_INFO]), | 37 userInfo: _emptyIfNull(m[_COMPONENT_USER_INFO]), |
32 domain: _emptyIfNull(m[_COMPONENT_DOMAIN]), | 38 domain: _emptyIfNull(m[_COMPONENT_DOMAIN]), |
33 port: _parseIntOrZero(m[_COMPONENT_PORT]), | 39 port: _parseIntOrZero(m[_COMPONENT_PORT]), |
34 path: _emptyIfNull(m[_COMPONENT_PATH]), | 40 path: _emptyIfNull(m[_COMPONENT_PATH]), |
35 query: _emptyIfNull(m[_COMPONENT_QUERY_DATA]), | 41 query: _emptyIfNull(m[_COMPONENT_QUERY_DATA]), |
36 fragment: _emptyIfNull(m[_COMPONENT_FRAGMENT])); | 42 fragment: _emptyIfNull(m[_COMPONENT_FRAGMENT])); |
37 | 43 |
38 const Uri.fromComponents({this.scheme: "", | 44 const Uri.fromComponents({this.scheme: "", |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 * segment = *pchar | 118 * segment = *pchar |
113 * segment-nz = 1*pchar | 119 * segment-nz = 1*pchar |
114 * segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" ) | 120 * segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" ) |
115 * ; non-zero-length segment without any colon ":" | 121 * ; non-zero-length segment without any colon ":" |
116 * | 122 * |
117 * pchar = unreserved / pct-encoded / sub-delims / ":" / "@" | 123 * pchar = unreserved / pct-encoded / sub-delims / ":" / "@" |
118 */ | 124 */ |
119 } | 125 } |
120 | 126 |
121 Uri resolve(String uri) { | 127 Uri resolve(String uri) { |
122 return resolveUri(new Uri.fromString(uri)); | 128 return resolveUri(Uri.parse(uri)); |
123 } | 129 } |
124 | 130 |
125 Uri resolveUri(Uri reference) { | 131 Uri resolveUri(Uri reference) { |
126 // From RFC 3986. | 132 // From RFC 3986. |
127 String targetScheme; | 133 String targetScheme; |
128 String targetUserInfo; | 134 String targetUserInfo; |
129 String targetDomain; | 135 String targetDomain; |
130 int targetPort; | 136 int targetPort; |
131 String targetPath; | 137 String targetPath; |
132 String targetQuery; | 138 String targetQuery; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } | 257 } |
252 | 258 |
253 static void _addIfNonEmpty(StringBuffer sb, String test, | 259 static void _addIfNonEmpty(StringBuffer sb, String test, |
254 String first, String second) { | 260 String first, String second) { |
255 if ("" != test) { | 261 if ("" != test) { |
256 sb.add(first == null ? "null" : first); | 262 sb.add(first == null ? "null" : first); |
257 sb.add(second == null ? "null" : second); | 263 sb.add(second == null ? "null" : second); |
258 } | 264 } |
259 } | 265 } |
260 } | 266 } |
OLD | NEW |