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

Unified Diff: client/json/dart_json.dart

Issue 9181003: Fix to the JsonStringifier in dart_json.dart to escape eols. The error messages that frog sends t... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 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 | « no previous file | client/tests/client/json/json_tests.dart » ('j') | client/tests/client/json/json_tests.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/json/dart_json.dart
===================================================================
--- client/json/dart_json.dart (revision 3201)
+++ client/json/dart_json.dart (working copy)
@@ -493,7 +493,8 @@
// TODO: add others.
static bool _needsEscape(int charCode) {
- return JsonTokenizer.QUOTE == charCode || JsonTokenizer.BACKSLASH == charCode;
+ return JsonTokenizer.QUOTE == charCode || JsonTokenizer.BACKSLASH == charCode
+ || JsonTokenizer.NEW_LINE == charCode || JsonTokenizer.LINE_FEED == charCode;
}
static void _escape(StringBuffer sb, String s) {
@@ -504,10 +505,16 @@
bool needsEscape = false;
final charCodes = new List<int>();
for (int i = 0; i < length; i++) {
- final int charCode = s.charCodeAt(i);
+ int charCode = s.charCodeAt(i);
if (_needsEscape(charCode)) {
charCodes.add(JsonTokenizer.BACKSLASH);
needsEscape = true;
+
+ if (JsonTokenizer.NEW_LINE == charCode) {
+ charCode = 110; // 'n'
Anton Muhin 2012/01/12 13:23:00 as an option see A_SMALL above. Ditto for r
devoncarew 2012/01/12 21:28:11 Done.
+ } else if (JsonTokenizer.LINE_FEED == charCode) {
+ charCode = 114; // 'r'
+ }
}
charCodes.add(charCode);
}
« no previous file with comments | « no previous file | client/tests/client/json/json_tests.dart » ('j') | client/tests/client/json/json_tests.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698