| 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 pub.utils; | 6 library pub.utils; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'dart:json' as json; | 10 import "dart:convert"; |
| 11 import 'dart:mirrors'; | 11 import 'dart:mirrors'; |
| 12 | 12 |
| 13 import "package:crypto/crypto.dart"; | 13 import "package:crypto/crypto.dart"; |
| 14 import 'package:path/path.dart' as path; | 14 import 'package:path/path.dart' as path; |
| 15 | 15 |
| 16 /// A pair of values. | 16 /// A pair of values. |
| 17 class Pair<E, F> { | 17 class Pair<E, F> { |
| 18 E first; | 18 E first; |
| 19 F last; | 19 F last; |
| 20 | 20 |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 var keys = data.keys.toList(); | 487 var keys = data.keys.toList(); |
| 488 keys.sort((a, b) => a.toString().compareTo(b.toString())); | 488 keys.sort((a, b) => a.toString().compareTo(b.toString())); |
| 489 | 489 |
| 490 var first = true; | 490 var first = true; |
| 491 for (var key in keys) { | 491 for (var key in keys) { |
| 492 if (!first) buffer.writeln(); | 492 if (!first) buffer.writeln(); |
| 493 first = false; | 493 first = false; |
| 494 | 494 |
| 495 var keyString = key; | 495 var keyString = key; |
| 496 if (key is! String || !_unquotableYamlString.hasMatch(key)) { | 496 if (key is! String || !_unquotableYamlString.hasMatch(key)) { |
| 497 keyString = json.stringify(key); | 497 keyString = JSON.encode(key); |
| 498 } | 498 } |
| 499 | 499 |
| 500 buffer.write('$indent$keyString:'); | 500 buffer.write('$indent$keyString:'); |
| 501 _stringify(true, indent, data[key]); | 501 _stringify(true, indent, data[key]); |
| 502 } | 502 } |
| 503 | 503 |
| 504 return; | 504 return; |
| 505 } | 505 } |
| 506 | 506 |
| 507 // Everything else we just stringify using JSON to handle escapes in | 507 // Everything else we just stringify using JSON to handle escapes in |
| 508 // strings and number formatting. | 508 // strings and number formatting. |
| 509 var string = data; | 509 var string = data; |
| 510 | 510 |
| 511 // Don't quote plain strings if not needed. | 511 // Don't quote plain strings if not needed. |
| 512 if (data is! String || !_unquotableYamlString.hasMatch(data)) { | 512 if (data is! String || !_unquotableYamlString.hasMatch(data)) { |
| 513 string = json.stringify(data); | 513 string = JSON.encode(data); |
| 514 } | 514 } |
| 515 | 515 |
| 516 if (isMapValue) { | 516 if (isMapValue) { |
| 517 buffer.write(' $string'); | 517 buffer.write(' $string'); |
| 518 } else { | 518 } else { |
| 519 buffer.write('$indent$string'); | 519 buffer.write('$indent$string'); |
| 520 } | 520 } |
| 521 } | 521 } |
| 522 | 522 |
| 523 _stringify(false, '', data); | 523 _stringify(false, '', data); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 548 error is DirectoryException || | 548 error is DirectoryException || |
| 549 error is FileException || | 549 error is FileException || |
| 550 error is HttpException || | 550 error is HttpException || |
| 551 error is HttpException || | 551 error is HttpException || |
| 552 error is LinkException || | 552 error is LinkException || |
| 553 error is OSError || | 553 error is OSError || |
| 554 error is ProcessException || | 554 error is ProcessException || |
| 555 error is SocketException || | 555 error is SocketException || |
| 556 error is WebSocketException; | 556 error is WebSocketException; |
| 557 } | 557 } |
| OLD | NEW |