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

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

Issue 718053003: Reduce foot-print of Error.safeToString on strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 | « sdk/lib/_internal/compiler/js_lib/js_helper.dart ('k') | tests/corelib/safe_to_string_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/errors.dart
diff --git a/sdk/lib/core/errors.dart b/sdk/lib/core/errors.dart
index f4509eb774968ed67531c05c56d03ee31c75ab07..30b9c2b6850dad0240e356e8828294cffc89ef51 100644
--- a/sdk/lib/core/errors.dart
+++ b/sdk/lib/core/errors.dart
@@ -79,52 +79,14 @@ class Error {
return object.toString();
}
if (object is String) {
- String string = object;
- StringBuffer buffer = new StringBuffer('"');
- const int TAB = 0x09;
- const int NEWLINE = 0x0a;
- const int CARRIGE_RETURN = 0x0d;
- const int BACKSLASH = 0x5c;
- const int DOUBLE_QUOTE = 0x22;
- const int DIGIT_ZERO = 0x30;
- const int LOWERCASE_A = 0x61;
- const int MAX_CONTROL = 0x1f;
- for (int i = 0; i < string.length; i++) {
- int codeUnit = string.codeUnitAt(i);
- if (codeUnit <= MAX_CONTROL) {
- if (codeUnit == NEWLINE) {
- buffer.write(r"\n");
- } else if (codeUnit == CARRIGE_RETURN) {
- buffer.write(r"\r");
- } else if (codeUnit == TAB) {
- buffer.write(r"\t");
- } else {
- buffer.write(r"\x");
- // Convert code in range 0x00 .. 0x1f to hex a two-digit hex string.
- if (codeUnit < 0x10) {
- buffer.write("0");
- } else {
- buffer.write("1");
- codeUnit -= 0x10;
- }
- // Single digit to hex.
- buffer.writeCharCode(codeUnit < 10 ? DIGIT_ZERO + codeUnit
- : LOWERCASE_A - 10 + codeUnit);
- }
- } else if (codeUnit == BACKSLASH) {
- buffer.write(r"\\");
- } else if (codeUnit == DOUBLE_QUOTE) {
- buffer.write(r'\"');
- } else {
- buffer.writeCharCode(codeUnit);
- }
- }
- buffer.write('"');
- return buffer.toString();
+ return _stringToSafeString(object);
}
return _objectToString(object);
}
+ /** Convert string to a valid string literal with no control characters. */
+ external static String _stringToSafeString(String string);
+
external static String _objectToString(Object object);
external StackTrace get stackTrace;
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/js_helper.dart ('k') | tests/corelib/safe_to_string_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698