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

Unified Diff: runtime/platform/json.cc

Issue 10801002: Add multibyte string support to debugger (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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
« runtime/bin/dbg_connection.cc ('K') | « runtime/platform/json.h ('k') | no next file » | 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 9716)
+++ runtime/platform/json.cc (working copy)
@@ -376,46 +376,83 @@
}
+void TextBuffer::PrintEscapedChar(uint32_t cp) {
+ 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 if (cp <= 0xffff) {
+ // Encode character as \uHHHH.
+ uint8_t digit0 = (cp & 0xf000) >> 12;
+ uint8_t digit1 = (cp & 0x0f00) >> 8;
+ uint8_t digit2 = (cp & 0x00f0) >> 4;
+ uint8_t digit3 = (cp & 0x000f);
+ Printf("\\u%c%c%c%c",
+ digit0 > 9 ? 'A' + (digit0 - 10) : '0' + digit0,
siva 2012/07/18 17:11:31 We have a Utils::IntToHexDigit(..) function for th
hausner 2012/07/18 22:20:36 Ok, but that function contains an assert that the
+ digit1 > 9 ? 'A' + (digit1 - 10) : '0' + digit1,
+ digit2 > 9 ? 'A' + (digit2 - 10) : '0' + digit2,
+ digit3 > 9 ? 'A' + (digit3 - 10) : '0' + digit3);
+ } else {
+ // Non-standard 32 bit character escape code of format \UHHHHHHHH.
+ uint8_t digit0 = (cp & 0xf0000000) >> 28;
+ uint8_t digit1 = (cp & 0x0f000000) >> 24;
+ uint8_t digit2 = (cp & 0x00f00000) >> 20;
+ uint8_t digit3 = (cp & 0x000f0000) >> 16;
+ uint8_t digit4 = (cp & 0x0000f000) >> 12;
+ uint8_t digit5 = (cp & 0x00000f00) >> 8;
+ uint8_t digit6 = (cp & 0x000000f0) >> 4;
+ uint8_t digit7 = (cp & 0x0000000f);
+ Printf("\\u%c%c%c%c%c%c%c%c",
+ digit0 > 9 ? 'A' + (digit0 - 10) : '0' + digit0,
+ digit1 > 9 ? 'A' + (digit1 - 10) : '0' + digit1,
+ digit2 > 9 ? 'A' + (digit2 - 10) : '0' + digit2,
+ digit3 > 9 ? 'A' + (digit3 - 10) : '0' + digit3,
+ digit4 > 9 ? 'A' + (digit4 - 10) : '0' + digit4,
+ digit5 > 9 ? 'A' + (digit5 - 10) : '0' + digit5,
+ digit6 > 9 ? 'A' + (digit6 - 10) : '0' + digit6,
+ digit7 > 9 ? 'A' + (digit7 - 10) : '0' + digit7);
+ }
+ }
+}
+
+
+void TextBuffer::PrintJsonString32(const uint32_t* codepoints,
+ intptr_t length) {
+ for (intptr_t i = 0; i < length; i++) {
+ uint32_t cp = codepoints[i];
+ PrintEscapedChar(cp);
+ }
+}
+
+
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);
- }
- }
+ PrintEscapedChar(cp);
}
}
« runtime/bin/dbg_connection.cc ('K') | « runtime/platform/json.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698