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

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: 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) {
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
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')
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.
94 .replaceAll('"', '$backslash"');
Lasse Reichstein Nielsen 2012/09/19 12:14:53 We SO need a computed replace to avoid these seque
95 return '"$escaped"';
96 }
97 return _objectToString(object);
98 }
99
100 external static _objectToString(Object object);
85 } 101 }
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