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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 class Error { 5 class Error {
6 const Error(); 6 const Error();
7 } 7 }
8 8
9 class AssertionError implements Error { 9 class AssertionError implements Error {
10 } 10 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 74 }
75 String formalParameters = sb.toString(); 75 String formalParameters = sb.toString();
76 return "NoSuchMethodError: incorrect number of arguments passed to " 76 return "NoSuchMethodError: incorrect number of arguments passed to "
77 "method named '$_functionName'\n" 77 "method named '$_functionName'\n"
78 "Receiver: ${safeToString(_receiver)}\n" 78 "Receiver: ${safeToString(_receiver)}\n"
79 "Tried calling: $_functionName($actualParameters)\n" 79 "Tried calling: $_functionName($actualParameters)\n"
80 "Found: $_functionName($formalParameters)"; 80 "Found: $_functionName($formalParameters)";
81 } 81 }
82 } 82 }
83 83
84 external static String safeToString(Object object); 84 static String safeToString(Object object) {
85 if (object is int || object is double || object is bool || null == object) {
86 return object.toString();
87 }
88 if (object is String) {
89 // TODO(ahe): Remove backslash when http://dartbug.com/4995 is fixed.
90 const backslash = '\\';
91 String escaped = object
92 .replaceAll('$backslash', '$backslash$backslash')
93 .replaceAll('\n', '${backslash}n')
94 .replaceAll('\r', '${backslash}r')
95 .replaceAll('"', '$backslash"');
96 return '"$escaped"';
97 }
98 return _objectToString(object);
99 }
100
101 external static _objectToString(Object object);
85 } 102 }
OLDNEW
« 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