Add string encoding to wire protocol

Also, add command to retrieve the source text of a given script.
Review URL: https://chromiumcodereview.appspot.com//10496006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@8220 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
hausner@google.com
2012-06-02 00:07:12 +00:00
parent 207a0bbb35
commit c39f48340d
7 changed files with 211 additions and 38 deletions
+49 -2
View File
@@ -92,8 +92,11 @@ void JSONScanner::ScanString() {
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 @@ intptr_t TextBuffer::Printf(const char* format, ...) {
}
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));
+1
View File
@@ -117,6 +117,7 @@ class TextBuffer : ValueObject {
~TextBuffer();
intptr_t Printf(const char* format, ...);
void PrintJsonString8(const uint8_t* codepoints, intptr_t length);
void Clear();