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

Side by Side 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, 6 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
« no previous file with comments | « runtime/platform/json.h ('k') | runtime/vm/debugger_api_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "platform/json.h" 5 #include "platform/json.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "platform/globals.h" 8 #include "platform/globals.h"
9 #include "platform/utils.h" 9 #include "platform/utils.h"
10 #include "vm/os.h" 10 #include "vm/os.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 void JSONScanner::ScanString() { 85 void JSONScanner::ScanString() {
86 ASSERT(*current_pos_ == '"'); 86 ASSERT(*current_pos_ == '"');
87 ++current_pos_; 87 ++current_pos_;
88 token_start_ = current_pos_; 88 token_start_ = current_pos_;
89 while (*current_pos_ != '"') { 89 while (*current_pos_ != '"') {
90 if (*current_pos_ == '\0') { 90 if (*current_pos_ == '\0') {
91 token_length_ = 0; 91 token_length_ = 0;
92 token_ = TokenIllegal; 92 token_ = TokenIllegal;
93 return; 93 return;
94 } else if (*current_pos_ == '\\') { 94 } else if (*current_pos_ == '\\') {
95 // TODO(hausner): Implement escape sequence. 95 ++current_pos_;
96 UNIMPLEMENTED(); 96 if (*current_pos_ == '"') {
97 // Consume escaped double quote.
98 ++current_pos_;
99 }
97 } else if (*current_pos_ < 0) { 100 } else if (*current_pos_ < 0) {
98 // UTF-8 not supported. 101 // UTF-8 not supported.
99 token_length_ = 0; 102 token_length_ = 0;
100 token_ = TokenIllegal; 103 token_ = TokenIllegal;
101 return; 104 return;
102 } else { 105 } else {
103 ++current_pos_; 106 ++current_pos_;
104 } 107 }
105 } 108 }
106 token_ = TokenString; 109 token_ = TokenString;
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 intptr_t len2 = OS::VSNPrint(buf_ + msg_len_, remaining, format, args2); 369 intptr_t len2 = OS::VSNPrint(buf_ + msg_len_, remaining, format, args2);
367 va_end(args2); 370 va_end(args2);
368 ASSERT(len == len2); 371 ASSERT(len == len2);
369 } 372 }
370 msg_len_ += len; 373 msg_len_ += len;
371 buf_[msg_len_] = '\0'; 374 buf_[msg_len_] = '\0';
372 return len; 375 return len;
373 } 376 }
374 377
375 378
379 void TextBuffer::PrintJsonString8(const uint8_t* codepoints, intptr_t length) {
380 for (intptr_t i = 0; i < length; i++) {
381 uint8_t cp = codepoints[i];
382 switch (cp) {
383 case '"':
384 Printf("%s", "\\\"");
385 break;
386 case '\\':
387 Printf("%s", "\\\\");
388 break;
389 case '/':
390 Printf("%s", "\\/");
391 break;
392 case '\b':
393 Printf("%s", "\\b");
394 break;
395 case '\f':
396 Printf("%s", "\\f");
397 break;
398 case '\n':
399 Printf("%s", "\\n");
400 break;
401 case '\r':
402 Printf("%s", "\\r");
403 break;
404 case '\t':
405 Printf("%s", "\\t");
406 break;
407 default:
408 if ((0x20 <= cp) && (cp <= 0x7e)) {
409 Printf("%c", cp);
410 } else {
411 // Encode character as \u00HH.
412 uint8_t digit2 = (cp & 0xf0) >> 4;
413 uint8_t digit3 = cp & 0xf;
414 Printf("\\u00%c%c",
415 digit2 > 9 ? 'A' + (digit2 - 10) : '0' + digit2,
416 digit3 > 9 ? 'A' + (digit3 - 10) : '0' + digit3);
417 }
418 }
419 }
420 }
421
422
376 void TextBuffer::GrowBuffer(intptr_t len) { 423 void TextBuffer::GrowBuffer(intptr_t len) {
377 intptr_t new_size = buf_size_ + len; 424 intptr_t new_size = buf_size_ + len;
378 char* new_buf = reinterpret_cast<char*>(realloc(buf_, new_size)); 425 char* new_buf = reinterpret_cast<char*>(realloc(buf_, new_size));
379 ASSERT(new_buf != NULL); 426 ASSERT(new_buf != NULL);
380 buf_ = new_buf; 427 buf_ = new_buf;
381 buf_size_ = new_size; 428 buf_size_ = new_size;
382 } 429 }
383 430
384 } // namespace dart 431 } // namespace dart
OLDNEW
« 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