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 utilslib; | 5 part of utilslib; |
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 */ |
11 class Uri extends uri.Uri { | 11 class Uri extends uri.Uri { |
12 /** | 12 /** |
13 * Parses a URL query string into a map. Because you can have multiple values | 13 * Parses a URL query string into a map. Because you can have multiple values |
14 * for the same parameter name, each parameter name maps to a list of | 14 * for the same parameter name, each parameter name maps to a list of |
15 * values. For example, '?a=b&c=d&a=e' would be parsed as | 15 * values. For example, '?a=b&c=d&a=e' would be parsed as |
16 * [{'a':['b','e'],'c':['d']}]. | 16 * [{'a':['b','e'],'c':['d']}]. |
17 */ | 17 */ |
18 // TODO(jmesserly): consolidate with new Uri.fromString(...) | 18 // TODO(jmesserly): consolidate with Uri.parse(...) |
19 static Map<String, List<String>> parseQuery(String queryString) { | 19 static Map<String, List<String>> parseQuery(String queryString) { |
20 final queryParams = new Map<String, List<String>>(); | 20 final queryParams = new Map<String, List<String>>(); |
21 if (queryString.startsWith('?')) { | 21 if (queryString.startsWith('?')) { |
22 final params = queryString.substring(1, queryString.length).split('&'); | 22 final params = queryString.substring(1, queryString.length).split('&'); |
23 for (final param in params) { | 23 for (final param in params) { |
24 List<String> parts = param.split('='); | 24 List<String> parts = param.split('='); |
25 if (parts.length == 2) { | 25 if (parts.length == 2) { |
26 // TODO(hiltonc) the name and value should be URL decoded. | 26 // TODO(hiltonc) the name and value should be URL decoded. |
27 String name = parts[0]; | 27 String name = parts[0]; |
28 String value = parts[1]; | 28 String value = parts[1]; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 return component.replaceAll('%3A', ':') | 70 return component.replaceAll('%3A', ':') |
71 .replaceAll('%2F', '/') | 71 .replaceAll('%2F', '/') |
72 .replaceAll('%3F', '?') | 72 .replaceAll('%3F', '?') |
73 .replaceAll('%3D', '=') | 73 .replaceAll('%3D', '=') |
74 .replaceAll('%26', '&') | 74 .replaceAll('%26', '&') |
75 .replaceAll('%20', ' '); | 75 .replaceAll('%20', ' '); |
76 } | 76 } |
77 | 77 |
78 Uri.fromString(String uriString) : super.fromString(uriString); | 78 Uri.fromString(String uriString) : super.fromString(uriString); |
79 } | 79 } |
OLD | NEW |