| 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 /// Generic utility functions. Stuff that should possibly be in core. | 5 /// Generic utility functions. Stuff that should possibly be in core. |
| 6 library utils; | 6 library utils; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 var index = toSplit.indexOf(pattern); | 291 var index = toSplit.indexOf(pattern); |
| 292 if (index == -1) return [toSplit]; | 292 if (index == -1) return [toSplit]; |
| 293 return [toSplit.substring(0, index), | 293 return [toSplit.substring(0, index), |
| 294 toSplit.substring(index + pattern.length)]; | 294 toSplit.substring(index + pattern.length)]; |
| 295 } | 295 } |
| 296 | 296 |
| 297 /// Adds additional query parameters to [url], overwriting the original | 297 /// Adds additional query parameters to [url], overwriting the original |
| 298 /// parameters if a name conflict occurs. | 298 /// parameters if a name conflict occurs. |
| 299 Uri addQueryParameters(Uri url, Map<String, String> parameters) { | 299 Uri addQueryParameters(Uri url, Map<String, String> parameters) { |
| 300 var queryMap = queryToMap(url.query); | 300 var queryMap = queryToMap(url.query); |
| 301 mapAddAll(queryMap, parameters); | 301 queryMap.addAll(parameters); |
| 302 return url.resolve("?${mapToQuery(queryMap)}"); | 302 return url.resolve("?${mapToQuery(queryMap)}"); |
| 303 } | 303 } |
| 304 | 304 |
| 305 /// Convert a URL query string (or `application/x-www-form-urlencoded` body) | 305 /// Convert a URL query string (or `application/x-www-form-urlencoded` body) |
| 306 /// into a [Map] from parameter names to values. | 306 /// into a [Map] from parameter names to values. |
| 307 Map<String, String> queryToMap(String queryList) { | 307 Map<String, String> queryToMap(String queryList) { |
| 308 var map = {}; | 308 var map = {}; |
| 309 for (var pair in queryList.split("&")) { | 309 for (var pair in queryList.split("&")) { |
| 310 var split = split1(pair, "="); | 310 var split = split1(pair, "="); |
| 311 if (split.isEmpty) continue; | 311 if (split.isEmpty) continue; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 335 /// Whether [uri1] and [uri2] are equal. This consider HTTP URIs to default to | 335 /// Whether [uri1] and [uri2] are equal. This consider HTTP URIs to default to |
| 336 /// port 80, and HTTPs URIs to default to port 443. | 336 /// port 80, and HTTPs URIs to default to port 443. |
| 337 bool urisEqual(Uri uri1, Uri uri2) => | 337 bool urisEqual(Uri uri1, Uri uri2) => |
| 338 canonicalizeUri(uri1) == canonicalizeUri(uri2); | 338 canonicalizeUri(uri1) == canonicalizeUri(uri2); |
| 339 | 339 |
| 340 /// Return [uri] with redundant port information removed. | 340 /// Return [uri] with redundant port information removed. |
| 341 Uri canonicalizeUri(Uri uri) { | 341 Uri canonicalizeUri(Uri uri) { |
| 342 return uri; | 342 return uri; |
| 343 } | 343 } |
| 344 | 344 |
| 345 /// Add all key/value pairs from [source] to [destination], overwriting any | |
| 346 /// pre-existing values. | |
| 347 void mapAddAll(Map destination, Map source) => | |
| 348 source.forEach((key, value) => destination[key] = value); | |
| 349 | |
| 350 /// Decodes a URL-encoded string. Unlike [Uri.decodeComponent], this includes | 345 /// Decodes a URL-encoded string. Unlike [Uri.decodeComponent], this includes |
| 351 /// replacing `+` with ` `. | 346 /// replacing `+` with ` `. |
| 352 String urlDecode(String encoded) => | 347 String urlDecode(String encoded) => |
| 353 Uri.decodeComponent(encoded.replaceAll("+", " ")); | 348 Uri.decodeComponent(encoded.replaceAll("+", " ")); |
| 354 | 349 |
| 355 /// Takes a simple data structure (composed of [Map]s, [Iterable]s, scalar | 350 /// Takes a simple data structure (composed of [Map]s, [Iterable]s, scalar |
| 356 /// objects, and [Future]s) and recursively resolves all the [Future]s contained | 351 /// objects, and [Future]s) and recursively resolves all the [Future]s contained |
| 357 /// within. Completes with the fully resolved structure. | 352 /// within. Completes with the fully resolved structure. |
| 358 Future awaitObject(object) { | 353 Future awaitObject(object) { |
| 359 // Unroll nested futures. | 354 // Unroll nested futures. |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 error is FileIOException || | 533 error is FileIOException || |
| 539 error is HttpException || | 534 error is HttpException || |
| 540 error is HttpParserException || | 535 error is HttpParserException || |
| 541 error is LinkIOException || | 536 error is LinkIOException || |
| 542 error is MimeMultipartException || | 537 error is MimeMultipartException || |
| 543 error is OSError || | 538 error is OSError || |
| 544 error is ProcessException || | 539 error is ProcessException || |
| 545 error is SocketIOException || | 540 error is SocketIOException || |
| 546 error is WebSocketException; | 541 error is WebSocketException; |
| 547 } | 542 } |
| OLD | NEW |