From c12957fdd8df34c552a18a9f19dd3c9d63ec8b21 Mon Sep 17 00:00:00 2001 From: Daniel Eichhorn Date: Sun, 5 Jun 2016 15:05:23 +0200 Subject: [PATCH] Fixed unicode handling - handling of special cases might still be problematic --- JsonStreamingParser.cpp | 8 ++++++-- JsonStreamingParser.h | 4 ++-- library.json | 2 +- library.properties | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/JsonStreamingParser.cpp b/JsonStreamingParser.cpp index 115a4e0..5fa2a24 100644 --- a/JsonStreamingParser.cpp +++ b/JsonStreamingParser.cpp @@ -332,7 +332,9 @@ void JsonStreamingParser::processUnicodeCharacter(char c) { if (unicodeBufferPos == 4) { int codepoint = getHexArrayAsDecimal(unicodeBuffer, unicodeBufferPos); - if (codepoint >= 0xD800 && codepoint < 0xDC00) { + endUnicodeCharacter(codepoint); + return; + /*if (codepoint >= 0xD800 && codepoint < 0xDC00) { unicodeHighSurrogate = codepoint; unicodeBufferPos = 0; state = STATE_UNICODE_SURROGATE; @@ -348,9 +350,10 @@ void JsonStreamingParser::processUnicodeCharacter(char c) { // throw new ParsingError($this->_line_number, // $this->_char_number, // "Invalid low surrogate following Unicode high surrogate."); + endUnicodeCharacter(codepoint); } else { endUnicodeCharacter(codepoint); - } + }*/ } } boolean JsonStreamingParser::isHexCharacter(char c) { @@ -390,6 +393,7 @@ void JsonStreamingParser::endUnicodeSurrogateInterstitial() { // "Expected '\\u' following a Unicode high surrogate. Got: " . // $unicode_escape); } + unicodeBufferPos = 0; unicodeEscapeBufferPos = 0; state = STATE_UNICODE; } diff --git a/JsonStreamingParser.h b/JsonStreamingParser.h index b044b29..926cd4e 100644 --- a/JsonStreamingParser.h +++ b/JsonStreamingParser.h @@ -65,10 +65,10 @@ class JsonStreamingParser { char buffer[BUFFER_MAX_LENGTH]; int bufferPos = 0; - char unicodeEscapeBuffer[128]; + char unicodeEscapeBuffer[10]; int unicodeEscapeBufferPos = 0; - char unicodeBuffer[128]; + char unicodeBuffer[10]; int unicodeBufferPos = 0; int characterCounter = 0; diff --git a/library.json b/library.json index efa62c4..0ca277b 100644 --- a/library.json +++ b/library.json @@ -10,7 +10,7 @@ "name": "Daniel Eichhorn", "url": "http://blog.squix.ch" }, - "version": "1.0.3", + "version": "1.0.4", "frameworks": "arduino", "platforms": "*", "examples": [ diff --git a/library.properties b/library.properties index e21598c..deb0208 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Json Streaming Parser -version=1.0.3 +version=1.0.4 author=Daniel Eichhorn maintainer=Daniel Eichhorn sentence=A very memory efficient library to parse (large) JSON objects on small devices