Chromium Code Reviews| 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:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'dart:typed_data'; | 10 import 'dart:typed_data'; |
| 11 | 11 |
| 12 import 'package:stack_trace/stack_trace.dart'; | |
| 13 | |
| 12 import 'byte_stream.dart'; | 14 import 'byte_stream.dart'; |
| 13 | 15 |
| 14 /// Converts a URL query string (or `application/x-www-form-urlencoded` body) | 16 /// Converts a URL query string (or `application/x-www-form-urlencoded` body) |
| 15 /// into a [Map] from parameter names to values. | 17 /// into a [Map] from parameter names to values. |
| 16 /// | 18 /// |
| 17 /// queryToMap("foo=bar&baz=bang&qux"); | 19 /// queryToMap("foo=bar&baz=bang&qux"); |
| 18 /// //=> {"foo": "bar", "baz": "bang", "qux": ""} | 20 /// //=> {"foo": "bar", "baz": "bang", "qux": ""} |
| 19 Map<String, String> queryToMap(String queryList, {Encoding encoding}) { | 21 Map<String, String> queryToMap(String queryList, {Encoding encoding}) { |
| 20 var map = {}; | 22 var map = {}; |
| 21 for (var pair in queryList.split("&")) { | 23 for (var pair in queryList.split("&")) { |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 /// The return values of all [Future]s are discarded. Any errors will cause the | 208 /// The return values of all [Future]s are discarded. Any errors will cause the |
| 207 /// iteration to stop and will be piped through the return value. | 209 /// iteration to stop and will be piped through the return value. |
| 208 Future forEachFuture(Iterable input, Future fn(element)) { | 210 Future forEachFuture(Iterable input, Future fn(element)) { |
| 209 var iterator = input.iterator; | 211 var iterator = input.iterator; |
| 210 Future nextElement(_) { | 212 Future nextElement(_) { |
| 211 if (!iterator.moveNext()) return new Future.value(); | 213 if (!iterator.moveNext()) return new Future.value(); |
| 212 return fn(iterator.current).then(nextElement); | 214 return fn(iterator.current).then(nextElement); |
| 213 } | 215 } |
| 214 return nextElement(null); | 216 return nextElement(null); |
| 215 } | 217 } |
| 218 | |
| 219 /// Like [Future.sync], but wraps the Future in [Chain.track] as well. | |
| 220 Future syncFuture(callback()) => Chain.track(new Future.sync(callback)); | |
|
Bob Nystrom
2013/12/05 17:35:46
Maybe this should be added to stack_trace itself?
nweiz
2013/12/05 19:27:45
I don't want to make it part of the public API sin
| |
| OLD | NEW |