Chromium Code Reviews| Index: dart/lib/core/errors.dart |
| diff --git a/dart/lib/core/errors.dart b/dart/lib/core/errors.dart |
| index 2c904587e225ccc233eccfeadb2c8597e19c2cf5..597d26a1bfdc97b927c110e1ccd185dd1a3e343a 100644 |
| --- a/dart/lib/core/errors.dart |
| +++ b/dart/lib/core/errors.dart |
| @@ -81,5 +81,21 @@ class NoSuchMethodError implements Error { |
| } |
| } |
| - external static String safeToString(Object object); |
| + static String safeToString(Object object) { |
| + if (object is int || object is double || object is bool || null == object) { |
|
Lasse Reichstein Nielsen
2012/09/19 12:14:53
The first two can be condensed to 'object is num'.
ahe
2012/09/19 15:59:45
No. I'll leave it as an exercise to the reader to
|
| + return object.toString(); |
| + } |
| + if (object is String) { |
| + // TODO(ahe): Remove backslash when http://dartbug.com/4995 is fixed. |
| + const backslash = '\\'; |
| + String escaped = object |
| + .replaceAll('$backslash', '$backslash$backslash') |
| + .replaceAll('\n', '${backslash}n') |
|
Lasse Reichstein Nielsen
2012/09/19 12:14:53
Ditto for "\r", which is also a "newline" in Dart.
ahe
2012/09/19 15:59:45
Done. Also extended the test.
|
| + .replaceAll('"', '$backslash"'); |
|
Lasse Reichstein Nielsen
2012/09/19 12:14:53
We SO need a computed replace to avoid these seque
|
| + return '"$escaped"'; |
| + } |
| + return _objectToString(object); |
| + } |
| + |
| + external static _objectToString(Object object); |
| } |