| 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:crypto'; | 9 import 'dart:crypto'; |
| 10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 } | 311 } |
| 312 | 312 |
| 313 // TODO(nweiz): remove this when issue 9068 has been fixed. | 313 // TODO(nweiz): remove this when issue 9068 has been fixed. |
| 314 /// Whether [uri1] and [uri2] are equal. This consider HTTP URIs to default to | 314 /// Whether [uri1] and [uri2] are equal. This consider HTTP URIs to default to |
| 315 /// port 80, and HTTPs URIs to default to port 443. | 315 /// port 80, and HTTPs URIs to default to port 443. |
| 316 bool urisEqual(Uri uri1, Uri uri2) => | 316 bool urisEqual(Uri uri1, Uri uri2) => |
| 317 canonicalizeUri(uri1) == canonicalizeUri(uri2); | 317 canonicalizeUri(uri1) == canonicalizeUri(uri2); |
| 318 | 318 |
| 319 /// Return [uri] with redundant port information removed. | 319 /// Return [uri] with redundant port information removed. |
| 320 Uri canonicalizeUri(Uri uri) { | 320 Uri canonicalizeUri(Uri uri) { |
| 321 if (uri == null) return null; |
| 322 |
| 321 var sansPort = new Uri.fromComponents( | 323 var sansPort = new Uri.fromComponents( |
| 322 scheme: uri.scheme, userInfo: uri.userInfo, domain: uri.domain, | 324 scheme: uri.scheme, userInfo: uri.userInfo, domain: uri.domain, |
| 323 path: uri.path, query: uri.query, fragment: uri.fragment); | 325 path: uri.path, query: uri.query, fragment: uri.fragment); |
| 324 if (uri.scheme == 'http' && uri.port == 80) return sansPort; | 326 if (uri.scheme == 'http' && uri.port == 80) return sansPort; |
| 325 if (uri.scheme == 'https' && uri.port == 443) return sansPort; | 327 if (uri.scheme == 'https' && uri.port == 443) return sansPort; |
| 326 return uri; | 328 return uri; |
| 327 } | 329 } |
| 328 | 330 |
| 329 /// Add all key/value pairs from [source] to [destination], overwriting any | 331 /// Add all key/value pairs from [source] to [destination], overwriting any |
| 330 /// pre-existing values. | 332 /// pre-existing values. |
| 331 void mapAddAll(Map destination, Map source) => | 333 void mapAddAll(Map destination, Map source) => |
| 332 source.forEach((key, value) => destination[key] = value); | 334 source.forEach((key, value) => destination[key] = value); |
| 333 | 335 |
| 334 /// Decodes a URL-encoded string. Unlike [decodeUriComponent], this includes | 336 /// Decodes a URL-encoded string. Unlike [decodeUriComponent], this includes |
| 335 /// replacing `+` with ` `. | 337 /// replacing `+` with ` `. |
| 336 String urlDecode(String encoded) => | 338 String urlDecode(String encoded) => |
| 337 decodeUriComponent(encoded.replaceAll("+", " ")); | 339 decodeUriComponent(encoded.replaceAll("+", " ")); |
| OLD | NEW |