From 47ee39179a92649f7df612f6fc7b9d114a825c21 Mon Sep 17 00:00:00 2001 From: Alligator Descartes Date: Mon, 5 Dec 2016 16:41:48 +0000 Subject: [PATCH] Added conditionals for non-Arduino compilation --- JsonListener.h | 4 ++++ JsonStreamingParser.cpp | 12 ++++++++---- JsonStreamingParser.h | 6 +++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/JsonListener.h b/JsonListener.h index 26c0d85..7cfb197 100644 --- a/JsonListener.h +++ b/JsonListener.h @@ -25,7 +25,11 @@ See more at http://blog.squix.ch and https://github.com/squix78/json-streaming-p #pragma once +#ifdef ARDUINO #include +#else +#include "MockArduino.h" +#endif class JsonListener { private: diff --git a/JsonStreamingParser.cpp b/JsonStreamingParser.cpp index 5fa2a24..3ae687f 100644 --- a/JsonStreamingParser.cpp +++ b/JsonStreamingParser.cpp @@ -26,13 +26,17 @@ See more at http://blog.squix.ch and https://github.com/squix78/json-streaming-p #include "JsonStreamingParser.h" JsonStreamingParser::JsonStreamingParser() { + reset(); +} + +void JsonStreamingParser::reset() { state = STATE_START_DOCUMENT; bufferPos = 0; unicodeEscapeBufferPos = 0; unicodeBufferPos = 0; characterCounter = 0; } - + void JsonStreamingParser::setListener(JsonListener* listener) { myListener = listener; } @@ -430,7 +434,7 @@ void JsonStreamingParser::endDocument() { void JsonStreamingParser::endTrue() { buffer[bufferPos] = '\0'; String value = String(buffer); - if (value.equals("true")) { + if (value == "true") { myListener->value("true"); } else { // throw new ParsingError($this->_line_number, $this->_char_number, @@ -443,7 +447,7 @@ void JsonStreamingParser::endTrue() { void JsonStreamingParser::endFalse() { buffer[bufferPos] = '\0'; String value = String(buffer); - if (value.equals("false")) { + if (value == "false") { myListener->value("false"); } else { // throw new ParsingError($this->_line_number, $this->_char_number, @@ -456,7 +460,7 @@ void JsonStreamingParser::endFalse() { void JsonStreamingParser::endNull() { buffer[bufferPos] = '\0'; String value = String(buffer); - if (value.equals("null")) { + if (value == "null") { myListener->value("null"); } else { // throw new ParsingError($this->_line_number, $this->_char_number, diff --git a/JsonStreamingParser.h b/JsonStreamingParser.h index 926cd4e..01ad895 100644 --- a/JsonStreamingParser.h +++ b/JsonStreamingParser.h @@ -25,7 +25,11 @@ See more at http://blog.squix.ch and https://github.com/squix78/json-streaming-p #pragma once +#ifdef ARDUINO #include +#else +#include "MockArduino.h" +#endif #include "JsonListener.h" #define STATE_START_DOCUMENT 0 @@ -131,5 +135,5 @@ class JsonStreamingParser { JsonStreamingParser(); void parse(char c); void setListener(JsonListener* listener); - + void reset(); };