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:uri'; | 8 import 'dart:uri'; |
9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
10 import 'dart:crypto'; | 10 import 'dart:crypto'; |
(...skipping 21 matching lines...) Expand all Loading... |
32 } | 32 } |
33 | 33 |
34 /// Convert a [Map] from parameter names to values to a URL query string. | 34 /// Convert a [Map] from parameter names to values to a URL query string. |
35 String mapToQuery(Map<String, String> map) { | 35 String mapToQuery(Map<String, String> map) { |
36 var pairs = <List<String>>[]; | 36 var pairs = <List<String>>[]; |
37 map.forEach((key, value) { | 37 map.forEach((key, value) { |
38 key = encodeUriComponent(key); | 38 key = encodeUriComponent(key); |
39 value = (value == null || value.isEmpty) ? null : encodeUriComponent(value); | 39 value = (value == null || value.isEmpty) ? null : encodeUriComponent(value); |
40 pairs.add([key, value]); | 40 pairs.add([key, value]); |
41 }); | 41 }); |
42 return Strings.join(pairs.mappedBy((pair) { | 42 return Strings.join(pairs.map((pair) { |
43 if (pair[1] == null) return pair[0]; | 43 if (pair[1] == null) return pair[0]; |
44 return "${pair[0]}=${pair[1]}"; | 44 return "${pair[0]}=${pair[1]}"; |
45 }), "&"); | 45 }), "&"); |
46 } | 46 } |
47 | 47 |
48 /// Add all key/value pairs from [source] to [destination], overwriting any | 48 /// Add all key/value pairs from [source] to [destination], overwriting any |
49 /// pre-existing values. | 49 /// pre-existing values. |
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); |
52 | 52 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 if (!paramString.trim().isEmpty) { | 107 if (!paramString.trim().isEmpty) { |
108 throw new FormatException('Invalid WWW-Authenticate header: "$header"'); | 108 throw new FormatException('Invalid WWW-Authenticate header: "$header"'); |
109 } | 109 } |
110 | 110 |
111 return new AuthenticateHeader(scheme, parameters); | 111 return new AuthenticateHeader(scheme, parameters); |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 /// Returns a [Future] that asynchronously completes to `null`. | 115 /// Returns a [Future] that asynchronously completes to `null`. |
116 Future get async => new Future.delayed(0, () => null); | 116 Future get async => new Future.delayed(0, () => null); |
OLD | NEW |