| 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 /** | 5 /** |
| 6 * A parsed URI, inspired by: | 6 * A parsed URI, inspired by: |
| 7 * http://closure-library.googlecode.com/svn/docs/class_goog_Uri.html | 7 * http://closure-library.googlecode.com/svn/docs/class_goog_Uri.html |
| 8 */ | 8 */ |
| 9 class Uri extends uri.Uri { | 9 class Uri extends uri.Uri { |
| 10 /** | 10 /** |
| 11 * Parses a URL query string into a map. Because you can have multiple values | 11 * Parses a URL query string into a map. Because you can have multiple values |
| 12 * for the same parameter name, each parameter name maps to a list of | 12 * for the same parameter name, each parameter name maps to a list of |
| 13 * values. For example, '?a=b&c=d&a=e' would be parsed as | 13 * values. For example, '?a=b&c=d&a=e' would be parsed as |
| 14 * [{'a':['b','e'],'c':['d']}]. | 14 * [{'a':['b','e'],'c':['d']}]. |
| 15 */ | 15 */ |
| 16 // TODO(jmesserly): consolidate with new Uri.fromString(...) | 16 // TODO(jmesserly): consolidate with new Uri.fromString(...) |
| 17 static Map<String, List<String>> parseQuery(String queryString) { | 17 static Map<String, List<String>> parseQuery(String queryString) { |
| 18 final queryParams = new Map<String, List<String>>(); | 18 final queryParams = new Map<String, List<String>>(); |
| 19 if (queryString.startsWith('?')) { | 19 if (queryString.startsWith('?')) { |
| 20 final params = queryString.substring(1, queryString.length).split('&'); | 20 final params = queryString.substring(1, queryString.length).split('&'); |
| 21 for (final param in params) { | 21 for (final param in params) { |
| 22 List<String> parts = param.split('='); | 22 List<String> parts = param.split('='); |
| 23 if (parts.length == 2) { | 23 if (parts.length == 2) { |
| 24 // TODO(hiltonc) the name and value should be URL decoded. | 24 // TODO(hiltonc) the name and value should be URL decoded. |
| 25 String name = parts[0]; | 25 String name = parts[0]; |
| 26 String value = parts[1]; | 26 String value = parts[1]; |
| 27 | 27 |
| 28 // Create a list of values for this name if not yet done. | 28 // Create a list of values for this name if not yet done. |
| 29 List values = queryParams[name]; | 29 List values = queryParams[name]; |
| 30 if (values === null) { | 30 if (values == null) { |
| 31 values = new List(); | 31 values = new List(); |
| 32 queryParams[name] = values; | 32 queryParams[name] = values; |
| 33 } | 33 } |
| 34 | 34 |
| 35 values.add(value); | 35 values.add(value); |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 return queryParams; | 39 return queryParams; |
| 40 } | 40 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 68 return component.replaceAll('%3A', ':') | 68 return component.replaceAll('%3A', ':') |
| 69 .replaceAll('%2F', '/') | 69 .replaceAll('%2F', '/') |
| 70 .replaceAll('%3F', '?') | 70 .replaceAll('%3F', '?') |
| 71 .replaceAll('%3D', '=') | 71 .replaceAll('%3D', '=') |
| 72 .replaceAll('%26', '&') | 72 .replaceAll('%26', '&') |
| 73 .replaceAll('%20', ' '); | 73 .replaceAll('%20', ' '); |
| 74 } | 74 } |
| 75 | 75 |
| 76 Uri.fromString(String uriString) : super.fromString(uriString); | 76 Uri.fromString(String uriString) : super.fromString(uriString); |
| 77 } | 77 } |
| OLD | NEW |