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

Unified Diff: runtime/platform/json.cc

Issue 10496006: Add string encoding to wire protocol (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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 | « runtime/platform/json.h ('k') | runtime/vm/debugger_api_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/platform/json.cc
===================================================================
--- runtime/platform/json.cc (revision 8218)
+++ runtime/platform/json.cc (working copy)
@@ -92,8 +92,11 @@
token_ = TokenIllegal;
return;
} else if (*current_pos_ == '\\') {
- // TODO(hausner): Implement escape sequence.
- UNIMPLEMENTED();
+ ++current_pos_;
+ if (*current_pos_ == '"') {
+ // Consume escaped double quote.
+ ++current_pos_;
+ }
} else if (*current_pos_ < 0) {
// UTF-8 not supported.
token_length_ = 0;
@@ -373,6 +376,50 @@
}
+void TextBuffer::PrintJsonString8(const uint8_t* codepoints, intptr_t length) {
+ for (intptr_t i = 0; i < length; i++) {
+ uint8_t cp = codepoints[i];
+ switch (cp) {
+ case '"':
+ Printf("%s", "\\\"");
+ break;
+ case '\\':
+ Printf("%s", "\\\\");
+ break;
+ case '/':
+ Printf("%s", "\\/");
+ break;
+ case '\b':
+ Printf("%s", "\\b");
+ break;
+ case '\f':
+ Printf("%s", "\\f");
+ break;
+ case '\n':
+ Printf("%s", "\\n");
+ break;
+ case '\r':
+ Printf("%s", "\\r");
+ break;
+ case '\t':
+ Printf("%s", "\\t");
+ break;
+ default:
+ if ((0x20 <= cp) && (cp <= 0x7e)) {
+ Printf("%c", cp);
+ } else {
+ // Encode character as \u00HH.
+ uint8_t digit2 = (cp & 0xf0) >> 4;
+ uint8_t digit3 = cp & 0xf;
+ Printf("\\u00%c%c",
+ digit2 > 9 ? 'A' + (digit2 - 10) : '0' + digit2,
+ digit3 > 9 ? 'A' + (digit3 - 10) : '0' + digit3);
+ }
+ }
+ }
+}
+
+
void TextBuffer::GrowBuffer(intptr_t len) {
intptr_t new_size = buf_size_ + len;
char* new_buf = reinterpret_cast<char*>(realloc(buf_, new_size));
« no previous file with comments | « runtime/platform/json.h ('k') | runtime/vm/debugger_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698