From fc4faacfec90d1c4e72c87a5f97c757b33cebf25 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sat, 18 Oct 2014 22:04:13 +0200 Subject: [PATCH] Renamed EscapedString into QuotedString --- .../{EscapedString.h => QuotedString.h} | 2 +- src/Internals/EscapedString.cpp | 6 ++--- src/Internals/JsonParser.cpp | 4 +-- src/Internals/JsonWriter.cpp | 4 +-- src/JsonObject.cpp | 1 - ...sts.cpp => QuotedString_PrintTo_Tests.cpp} | 26 +++++++++---------- 6 files changed, 21 insertions(+), 22 deletions(-) rename include/ArduinoJson/Internals/{EscapedString.h => QuotedString.h} (92%) rename test/{EscapedString_PrintTo_Tests.cpp => QuotedString_PrintTo_Tests.cpp} (61%) diff --git a/include/ArduinoJson/Internals/EscapedString.h b/include/ArduinoJson/Internals/QuotedString.h similarity index 92% rename from include/ArduinoJson/Internals/EscapedString.h rename to include/ArduinoJson/Internals/QuotedString.h index 311f7398..794cc7d2 100644 --- a/include/ArduinoJson/Internals/EscapedString.h +++ b/include/ArduinoJson/Internals/QuotedString.h @@ -11,7 +11,7 @@ namespace ArduinoJson { namespace Internals { - class EscapedString + class QuotedString { public: static size_t printTo(const char*, Print*); diff --git a/src/Internals/EscapedString.cpp b/src/Internals/EscapedString.cpp index fc7c816e..b1fa57e6 100644 --- a/src/Internals/EscapedString.cpp +++ b/src/Internals/EscapedString.cpp @@ -3,7 +3,7 @@ * Benoit Blanchon 2014 - MIT License */ -#include "ArduinoJson/Internals/EscapedString.h" +#include "ArduinoJson/Internals/QuotedString.h" using namespace ArduinoJson::Internals; @@ -30,7 +30,7 @@ static inline size_t printCharTo(char c, Print* p) : p->write(c); } -size_t EscapedString::printTo(const char* s, Print* p) +size_t QuotedString::printTo(const char* s, Print* p) { if (!s) return p->print("null"); @@ -63,7 +63,7 @@ static inline bool isQuote(char c) return c == '\"' || c == '\''; } -char* EscapedString::extractFrom(char* input, char** endPtr) +char* QuotedString::extractFrom(char* input, char** endPtr) { char firstChar = *input; char stopChar; diff --git a/src/Internals/JsonParser.cpp b/src/Internals/JsonParser.cpp index 4c986f36..eceb41df 100644 --- a/src/Internals/JsonParser.cpp +++ b/src/Internals/JsonParser.cpp @@ -4,7 +4,7 @@ #include #include "ArduinoJson/JsonBuffer.h" -#include "ArduinoJson/Internals/EscapedString.h" +#include "ArduinoJson/Internals/QuotedString.h" using namespace ArduinoJson::Internals; @@ -176,6 +176,6 @@ JsonNode* JsonParser::parseNull() JsonNode* JsonParser::parseString() { - const char* s = EscapedString::extractFrom(_ptr, &_ptr); + const char* s = QuotedString::extractFrom(_ptr, &_ptr); return _buffer->createStringNode(s); } diff --git a/src/Internals/JsonWriter.cpp b/src/Internals/JsonWriter.cpp index c005c73b..f95d4e2e 100644 --- a/src/Internals/JsonWriter.cpp +++ b/src/Internals/JsonWriter.cpp @@ -1,11 +1,11 @@ #include "ArduinoJson/Internals/JsonWriter.h" -#include "ArduinoJson/Internals/EscapedString.h" +#include "ArduinoJson/Internals/QuotedString.h" using namespace ArduinoJson::Internals; void JsonWriter::writeString(char const* value) { - _length += EscapedString::printTo(value, _sink); + _length += QuotedString::printTo(value, _sink); } void JsonWriter::writeInteger(long value) diff --git a/src/JsonObject.cpp b/src/JsonObject.cpp index cb9271fc..874e9045 100644 --- a/src/JsonObject.cpp +++ b/src/JsonObject.cpp @@ -4,7 +4,6 @@ #include "ArduinoJson/JsonBuffer.h" #include "ArduinoJson/JsonValue.h" -#include "ArduinoJson/Internals/EscapedString.h" #include "ArduinoJson/Internals/JsonNode.h" #include "ArduinoJson/Internals/StringBuilder.h" diff --git a/test/EscapedString_PrintTo_Tests.cpp b/test/QuotedString_PrintTo_Tests.cpp similarity index 61% rename from test/EscapedString_PrintTo_Tests.cpp rename to test/QuotedString_PrintTo_Tests.cpp index 18f22d9f..f9a57ab3 100644 --- a/test/EscapedString_PrintTo_Tests.cpp +++ b/test/QuotedString_PrintTo_Tests.cpp @@ -1,17 +1,17 @@ #include -#include +#include #include using namespace ArduinoJson::Internals; -class EscapedString_PrintTo_Tests : public testing::Test +class QuotedString_PrintTo_Tests : public testing::Test { protected: void whenInputIs(const char* input) { StringBuilder sb(buffer, sizeof(buffer)); - returnValue = EscapedString::printTo(input, &sb); + returnValue = QuotedString::printTo(input, &sb); } void outputMustBe(const char* expected) @@ -25,61 +25,61 @@ private: size_t returnValue; }; -TEST_F(EscapedString_PrintTo_Tests, Null) +TEST_F(QuotedString_PrintTo_Tests, Null) { whenInputIs(0); outputMustBe("null"); } -TEST_F(EscapedString_PrintTo_Tests, EmptyString) +TEST_F(QuotedString_PrintTo_Tests, EmptyString) { whenInputIs(""); outputMustBe("\"\""); } -TEST_F(EscapedString_PrintTo_Tests, QuotationMark) +TEST_F(QuotedString_PrintTo_Tests, QuotationMark) { whenInputIs("\""); outputMustBe("\"\\\"\""); } -TEST_F(EscapedString_PrintTo_Tests, ReverseSolidus) +TEST_F(QuotedString_PrintTo_Tests, ReverseSolidus) { whenInputIs("\\"); outputMustBe("\"\\\\\""); } -TEST_F(EscapedString_PrintTo_Tests, Solidus) +TEST_F(QuotedString_PrintTo_Tests, Solidus) { whenInputIs("/"); outputMustBe("\"/\""); // but the JSON format allows \/ } -TEST_F(EscapedString_PrintTo_Tests, Backspace) +TEST_F(QuotedString_PrintTo_Tests, Backspace) { whenInputIs("\b"); outputMustBe("\"\\b\""); } -TEST_F(EscapedString_PrintTo_Tests, Formfeed) +TEST_F(QuotedString_PrintTo_Tests, Formfeed) { whenInputIs("\f"); outputMustBe("\"\\f\""); } -TEST_F(EscapedString_PrintTo_Tests, Newline) +TEST_F(QuotedString_PrintTo_Tests, Newline) { whenInputIs("\n"); outputMustBe("\"\\n\""); } -TEST_F(EscapedString_PrintTo_Tests, CarriageReturn) +TEST_F(QuotedString_PrintTo_Tests, CarriageReturn) { whenInputIs("\r"); outputMustBe("\"\\r\""); } -TEST_F(EscapedString_PrintTo_Tests, HorizontalTab) +TEST_F(QuotedString_PrintTo_Tests, HorizontalTab) { whenInputIs("\t"); outputMustBe("\"\\t\"");