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 http.utils; | 5 library http.utils; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:typed_data'; | 9 import 'dart:typed_data'; |
10 | 10 |
11 import 'package:stack_trace/stack_trace.dart'; | |
12 | |
13 import 'byte_stream.dart'; | 11 import 'byte_stream.dart'; |
14 | 12 |
15 /// Converts a URL query string (or `application/x-www-form-urlencoded` body) | 13 /// Converts a URL query string (or `application/x-www-form-urlencoded` body) |
16 /// into a [Map] from parameter names to values. | 14 /// into a [Map] from parameter names to values. |
17 /// | 15 /// |
18 /// queryToMap("foo=bar&baz=bang&qux"); | 16 /// queryToMap("foo=bar&baz=bang&qux"); |
19 /// //=> {"foo": "bar", "baz": "bang", "qux": ""} | 17 /// //=> {"foo": "bar", "baz": "bang", "qux": ""} |
20 Map<String, String> queryToMap(String queryList, {Encoding encoding}) { | 18 Map<String, String> queryToMap(String queryList, {Encoding encoding}) { |
21 var map = {}; | 19 var map = {}; |
22 for (var pair in queryList.split("&")) { | 20 for (var pair in queryList.split("&")) { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 } | 187 } |
190 | 188 |
191 int get hashCode => first.hashCode ^ last.hashCode; | 189 int get hashCode => first.hashCode ^ last.hashCode; |
192 } | 190 } |
193 | 191 |
194 /// Configures [future] so that its result (success or exception) is passed on | 192 /// Configures [future] so that its result (success or exception) is passed on |
195 /// to [completer]. | 193 /// to [completer]. |
196 void chainToCompleter(Future future, Completer completer) { | 194 void chainToCompleter(Future future, Completer completer) { |
197 future.then(completer.complete, onError: completer.completeError); | 195 future.then(completer.complete, onError: completer.completeError); |
198 } | 196 } |
199 | |
200 /// Like [Future.sync], but wraps the Future in [Chain.track] as well. | |
201 Future syncFuture(callback()) => Chain.track(new Future.sync(callback)); | |
OLD | NEW |