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

Unified Diff: runtime/platform/text_buffer.cc

Issue 2081433002: Use official JSON encoding for stream (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Removed STL from code Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/json_stream.cc » ('j') | runtime/vm/json_stream.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/platform/text_buffer.cc
diff --git a/runtime/platform/text_buffer.cc b/runtime/platform/text_buffer.cc
index 1536dac13b3adb2f7a329e1eb3b30a4abe86b2cb..24dfb018f0bc3c2a4b8c9de81d788f68aa975ce1 100644
--- a/runtime/platform/text_buffer.cc
+++ b/runtime/platform/text_buffer.cc
@@ -8,6 +8,7 @@
#include "platform/globals.h"
#include "platform/utils.h"
#include "vm/os.h"
+#include "vm/unicode.h"
namespace dart {
@@ -78,9 +79,8 @@ intptr_t TextBuffer::Printf(const char* format, ...) {
return len;
}
-
-// Write a UTF-16 code unit so it can be read by a JSON parser in a string
-// literal. Use escape sequences for characters other than printable ASCII.
+// Write a UTF-32 code unit so it can be read by a JSON parser in a string
+// literal. Use official encoding from JSON specification. http://json.org/
void TextBuffer::EscapeAndAddCodeUnit(uint32_t codeunit) {
rmacnak 2016/06/21 16:56:56 Perhaps this should be split into EscapeAndAddUTF1
cbernaschina 2016/06/21 21:24:43 Done.
switch (codeunit) {
case '"':
@@ -108,27 +108,10 @@ void TextBuffer::EscapeAndAddCodeUnit(uint32_t codeunit) {
Printf("%s", "\\t");
break;
default:
- if (codeunit < 0x20) {
- // Encode character as \u00HH.
- uint32_t digit2 = (codeunit >> 4) & 0xf;
- uint32_t digit3 = (codeunit & 0xf);
- Printf("\\u00%c%c",
- digit2 > 9 ? 'A' + (digit2 - 10) : '0' + digit2,
- digit3 > 9 ? 'A' + (digit3 - 10) : '0' + digit3);
- } else if (codeunit > 127) {
- // Encode character as \uHHHH.
- uint32_t digit0 = (codeunit >> 12) & 0xf;
- uint32_t digit1 = (codeunit >> 8) & 0xf;
- uint32_t digit2 = (codeunit >> 4) & 0xf;
- uint32_t digit3 = (codeunit & 0xf);
- Printf("\\u%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);
- } else {
- AddChar(codeunit);
- }
+ char encoded[6];
+ intptr_t length = Utf8::Length(codeunit);
+ Utf8::Encode(codeunit, encoded);
+ AddRaw(reinterpret_cast<uint8_t*>(encoded), length);
}
}
« no previous file with comments | « no previous file | runtime/vm/json_stream.cc » ('j') | runtime/vm/json_stream.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698