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.core; | 5 part of dart.core; |
6 | 6 |
7 /** | 7 /** |
8 * A parsed URI, as specified by RFC-3986, http://tools.ietf.org/html/rfc3986. | 8 * A parsed URI, as specified by RFC-3986, http://tools.ietf.org/html/rfc3986. |
9 */ | 9 */ |
10 class Uri { | 10 class Uri { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 } else if (scheme == "https" && port == 443) { | 171 } else if (scheme == "https" && port == 443) { |
172 _port = 0; | 172 _port = 0; |
173 } else { | 173 } else { |
174 _port = port; | 174 _port = port; |
175 } | 175 } |
176 // Fill the path. | 176 // Fill the path. |
177 _path = _makePath(path, pathSegments); | 177 _path = _makePath(path, pathSegments); |
178 } | 178 } |
179 | 179 |
180 /** | 180 /** |
181 * Create a new `http` URI with authority, path and query. | |
floitsch
2013/06/17 14:29:01
Creates
Søren Gjesse
2013/06/18 06:05:34
Done.
| |
182 * | |
183 * // Create the URI http://example.org/path?q=abc. | |
184 * Uri uri = new Uri.http("example.org", "/path", { "q" : "abc" }); | |
185 * | |
186 * The `scheme` is always set to `http`. | |
187 * | |
188 * The `userInfo`, `host` and `port` components are set from the | |
189 * [authority] argument. | |
190 * | |
191 * The `path` component is set from the [unencodedPath] | |
192 * argument. The path passed should not be encoded as this | |
floitsch
2013/06/17 14:29:01
must not
Søren Gjesse
2013/06/18 06:05:34
Done.
| |
193 * constructor will encode the path. | |
floitsch
2013/06/17 14:29:01
encodes
Søren Gjesse
2013/06/18 06:05:34
Done.
| |
194 * | |
195 * The `query` component is set from the [queryParameters] argument. | |
floitsch
2013/06/17 14:29:01
from the optional
Søren Gjesse
2013/06/18 06:05:34
Done.
| |
196 */ | |
floitsch
2013/06/17 14:29:01
Maybe add some examples. In particular showing wha
floitsch
2013/06/17 14:31:34
Also add example with space in path.
Søren Gjesse
2013/06/18 06:05:34
Done.
Søren Gjesse
2013/06/18 06:05:34
Done.
| |
197 factory Uri.http(String authority, | |
198 String unencodedPath, | |
199 [Map<String, String> queryParameters]) { | |
200 return _makeHttpUri("http", authority, unencodedPath, queryParameters); | |
201 } | |
202 | |
203 /** | |
204 * Create a new `https` URI with authority, path and query. | |
floitsch
2013/06/17 14:29:01
Creates
Søren Gjesse
2013/06/18 06:05:34
Done.
| |
205 * | |
206 * See [Uri.http] constructor for information on the arguments. | |
floitsch
2013/06/17 14:29:01
This constructor is the same as [Uri.http] except
Søren Gjesse
2013/06/18 06:05:34
Done.
| |
207 */ | |
208 factory Uri.https(String authority, | |
209 String unencodedPath, | |
210 [Map<String, String> queryParameters]) { | |
211 return _makeHttpUri("https", authority, unencodedPath, queryParameters); | |
212 } | |
213 | |
214 static Uri _makeHttpUri(String scheme, | |
215 String authority, | |
216 String unencodedPath, | |
217 Map<String, String> queryParameters) { | |
218 var userInfo = ""; | |
219 var host = ""; | |
220 var port = 0; | |
221 | |
222 var hostStart = 0; | |
223 // Split off the user info. | |
224 bool hasUserInfo = false; | |
225 for (int i = 0; i < authority.length; i++) { | |
226 if (authority.codeUnitAt(i) == _AT_SIGN) { | |
227 hasUserInfo = true; | |
228 userInfo = authority.substring(0, i); | |
229 hostStart = i + 1; | |
230 break; | |
231 } | |
232 } | |
233 // Split host and port. | |
234 bool hasPort = false; | |
235 for (int i = hostStart; i < authority.length; i++) { | |
236 if (authority.codeUnitAt(i) == _COLON) { | |
237 hasPort = true; | |
238 host = authority.substring(hostStart, i); | |
239 if (!host.isEmpty) { | |
240 var portString = authority.substring(i + 1); | |
241 if (portString.isNotEmpty) port = int.parse(portString); | |
242 } | |
243 break; | |
244 } | |
245 } | |
246 if (!hasPort) { | |
247 host = hasUserInfo ? authority.substring(hostStart) : authority; | |
248 } | |
249 | |
250 return new Uri(scheme: scheme, | |
251 userInfo: userInfo, | |
252 host: host, | |
253 port: port, | |
254 pathSegments: unencodedPath.split("/"), | |
255 queryParameters: queryParameters); | |
256 } | |
257 | |
258 /** | |
181 * Returns the URI path split into its segments. Each of the | 259 * Returns the URI path split into its segments. Each of the |
182 * segments in the returned list have been decoded. If the path is | 260 * segments in the returned list have been decoded. If the path is |
183 * empty the empty list will be returned. A leading slash `/` does | 261 * empty the empty list will be returned. A leading slash `/` does |
184 * not affect the segments returned. | 262 * not affect the segments returned. |
185 * | 263 * |
186 * The returned list is unmodifiable and will throw [UnsupportedError] on any | 264 * The returned list is unmodifiable and will throw [UnsupportedError] on any |
187 * calls that would mutate it. | 265 * calls that would mutate it. |
188 */ | 266 */ |
189 List<String> get pathSegments { | 267 List<String> get pathSegments { |
190 if (_pathSegments == null) { | 268 if (_pathSegments == null) { |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
739 }); | 817 }); |
740 } | 818 } |
741 | 819 |
742 // Frequently used character codes. | 820 // Frequently used character codes. |
743 static const int _PERCENT = 0x25; | 821 static const int _PERCENT = 0x25; |
744 static const int _PLUS = 0x2B; | 822 static const int _PLUS = 0x2B; |
745 static const int _SLASH = 0x2F; | 823 static const int _SLASH = 0x2F; |
746 static const int _ZERO = 0x30; | 824 static const int _ZERO = 0x30; |
747 static const int _NINE = 0x39; | 825 static const int _NINE = 0x39; |
748 static const int _COLON = 0x3A; | 826 static const int _COLON = 0x3A; |
827 static const int _AT_SIGN = 0x40; | |
749 static const int _UPPER_CASE_A = 0x41; | 828 static const int _UPPER_CASE_A = 0x41; |
750 static const int _UPPER_CASE_F = 0x46; | 829 static const int _UPPER_CASE_F = 0x46; |
751 static const int _LOWER_CASE_A = 0x61; | 830 static const int _LOWER_CASE_A = 0x61; |
752 static const int _LOWER_CASE_F = 0x66; | 831 static const int _LOWER_CASE_F = 0x66; |
753 | 832 |
754 /** | 833 /** |
755 * This is the internal implementation of JavaScript's encodeURI function. | 834 * This is the internal implementation of JavaScript's encodeURI function. |
756 * It encodes all characters in the string [text] except for those | 835 * It encodes all characters in the string [text] except for those |
757 * that appear in [canonicalTable], and returns the escaped string. | 836 * that appear in [canonicalTable], and returns the escaped string. |
758 */ | 837 */ |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1034 void clear() { | 1113 void clear() { |
1035 throw new UnsupportedError("Cannot modify an unmodifiable map"); | 1114 throw new UnsupportedError("Cannot modify an unmodifiable map"); |
1036 } | 1115 } |
1037 void forEach(void f(K key, V value)) => _map.forEach(f); | 1116 void forEach(void f(K key, V value)) => _map.forEach(f); |
1038 Iterable<K> get keys => _map.keys; | 1117 Iterable<K> get keys => _map.keys; |
1039 Iterable<V> get values => _map.values; | 1118 Iterable<V> get values => _map.values; |
1040 int get length => _map.length; | 1119 int get length => _map.length; |
1041 bool get isEmpty => _map.isEmpty; | 1120 bool get isEmpty => _map.isEmpty; |
1042 bool get isNotEmpty => _map.isNotEmpty; | 1121 bool get isNotEmpty => _map.isNotEmpty; |
1043 } | 1122 } |
OLD | NEW |