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 utils; | 5 library utils; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:crypto'; | 8 import 'dart:crypto'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'dart:scalarlist'; | 10 import 'dart:scalarlist'; |
(...skipping 20 matching lines...) Expand all Loading... |
31 } | 31 } |
32 | 32 |
33 /// Converts a [Map] from parameter names to values to a URL query string. | 33 /// Converts a [Map] from parameter names to values to a URL query string. |
34 /// | 34 /// |
35 /// mapToQuery({"foo": "bar", "baz": "bang"}); | 35 /// mapToQuery({"foo": "bar", "baz": "bang"}); |
36 /// //=> "foo=bar&baz=bang" | 36 /// //=> "foo=bar&baz=bang" |
37 String mapToQuery(Map<String, String> map) { | 37 String mapToQuery(Map<String, String> map) { |
38 var pairs = <List<String>>[]; | 38 var pairs = <List<String>>[]; |
39 map.forEach((key, value) => | 39 map.forEach((key, value) => |
40 pairs.add([encodeUriComponent(key), encodeUriComponent(value)])); | 40 pairs.add([encodeUriComponent(key), encodeUriComponent(value)])); |
41 return Strings.join(pairs.map((pair) => "${pair[0]}=${pair[1]}"), "&"); | 41 return pairs.map((pair) => "${pair[0]}=${pair[1]}").join("&"); |
42 } | 42 } |
43 | 43 |
44 /// Adds all key/value pairs from [source] to [destination], overwriting any | 44 /// Adds all key/value pairs from [source] to [destination], overwriting any |
45 /// pre-existing values. | 45 /// pre-existing values. |
46 /// | 46 /// |
47 /// var a = {"foo": "bar", "baz": "bang"}; | 47 /// var a = {"foo": "bar", "baz": "bang"}; |
48 /// mapAddAll(a, {"baz": "zap", "qux": "quux"}); | 48 /// mapAddAll(a, {"baz": "zap", "qux": "quux"}); |
49 /// a; //=> {"foo": "bar", "baz": "zap", "qux": "quux"} | 49 /// a; //=> {"foo": "bar", "baz": "zap", "qux": "quux"} |
50 void mapAddAll(Map destination, Map source) => | 50 void mapAddAll(Map destination, Map source) => |
51 source.forEach((key, value) => destination[key] = value); | 51 source.forEach((key, value) => destination[key] = value); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 /// [StreamController]. This exists to work around issue 8310. | 315 /// [StreamController]. This exists to work around issue 8310. |
316 Stream wrapStream(Stream stream) { | 316 Stream wrapStream(Stream stream) { |
317 var controller = stream.isBroadcast | 317 var controller = stream.isBroadcast |
318 ? new StreamController.broadcast() | 318 ? new StreamController.broadcast() |
319 : new StreamController(); | 319 : new StreamController(); |
320 stream.listen(controller.add, | 320 stream.listen(controller.add, |
321 onError: (e) => controller.signalError(e), | 321 onError: (e) => controller.signalError(e), |
322 onDone: controller.close); | 322 onDone: controller.close); |
323 return controller.stream; | 323 return controller.stream; |
324 } | 324 } |
OLD | NEW |