Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(825)

Unified Diff: dart/lib/core/errors.dart

Issue 10943027: Handle backslashes and newlines when escaping strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dart/lib/compiler/implementation/lib/core_patch.dart ('k') | dart/runtime/lib/errors_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/lib/core/errors.dart
diff --git a/dart/lib/core/errors.dart b/dart/lib/core/errors.dart
index 2c904587e225ccc233eccfeadb2c8597e19c2cf5..659810714f30d829a97fc67b27794ca590067029 100644
--- a/dart/lib/core/errors.dart
+++ b/dart/lib/core/errors.dart
@@ -81,5 +81,22 @@ 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) {
+ 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')
+ .replaceAll('\r', '${backslash}r')
+ .replaceAll('"', '$backslash"');
+ return '"$escaped"';
+ }
+ return _objectToString(object);
+ }
+
+ external static _objectToString(Object object);
}
« no previous file with comments | « dart/lib/compiler/implementation/lib/core_patch.dart ('k') | dart/runtime/lib/errors_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698