Renamed EscapedString into QuotedString

This commit is contained in:
Benoit Blanchon
2014-10-18 22:04:13 +02:00
parent bbc2aa4f2a
commit fc4faacfec
6 changed files with 21 additions and 22 deletions

View File

@ -11,7 +11,7 @@ namespace ArduinoJson
{ {
namespace Internals namespace Internals
{ {
class EscapedString class QuotedString
{ {
public: public:
static size_t printTo(const char*, Print*); static size_t printTo(const char*, Print*);

View File

@ -3,7 +3,7 @@
* Benoit Blanchon 2014 - MIT License * Benoit Blanchon 2014 - MIT License
*/ */
#include "ArduinoJson/Internals/EscapedString.h" #include "ArduinoJson/Internals/QuotedString.h"
using namespace ArduinoJson::Internals; using namespace ArduinoJson::Internals;
@ -30,7 +30,7 @@ static inline size_t printCharTo(char c, Print* p)
: p->write(c); : 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"); if (!s) return p->print("null");
@ -63,7 +63,7 @@ static inline bool isQuote(char c)
return c == '\"' || c == '\''; return c == '\"' || c == '\'';
} }
char* EscapedString::extractFrom(char* input, char** endPtr) char* QuotedString::extractFrom(char* input, char** endPtr)
{ {
char firstChar = *input; char firstChar = *input;
char stopChar; char stopChar;

View File

@ -4,7 +4,7 @@
#include <ctype.h> #include <ctype.h>
#include "ArduinoJson/JsonBuffer.h" #include "ArduinoJson/JsonBuffer.h"
#include "ArduinoJson/Internals/EscapedString.h" #include "ArduinoJson/Internals/QuotedString.h"
using namespace ArduinoJson::Internals; using namespace ArduinoJson::Internals;
@ -176,6 +176,6 @@ JsonNode* JsonParser::parseNull()
JsonNode* JsonParser::parseString() JsonNode* JsonParser::parseString()
{ {
const char* s = EscapedString::extractFrom(_ptr, &_ptr); const char* s = QuotedString::extractFrom(_ptr, &_ptr);
return _buffer->createStringNode(s); return _buffer->createStringNode(s);
} }

View File

@ -1,11 +1,11 @@
#include "ArduinoJson/Internals/JsonWriter.h" #include "ArduinoJson/Internals/JsonWriter.h"
#include "ArduinoJson/Internals/EscapedString.h" #include "ArduinoJson/Internals/QuotedString.h"
using namespace ArduinoJson::Internals; using namespace ArduinoJson::Internals;
void JsonWriter::writeString(char const* value) void JsonWriter::writeString(char const* value)
{ {
_length += EscapedString::printTo(value, _sink); _length += QuotedString::printTo(value, _sink);
} }
void JsonWriter::writeInteger(long value) void JsonWriter::writeInteger(long value)

View File

@ -4,7 +4,6 @@
#include "ArduinoJson/JsonBuffer.h" #include "ArduinoJson/JsonBuffer.h"
#include "ArduinoJson/JsonValue.h" #include "ArduinoJson/JsonValue.h"
#include "ArduinoJson/Internals/EscapedString.h"
#include "ArduinoJson/Internals/JsonNode.h" #include "ArduinoJson/Internals/JsonNode.h"
#include "ArduinoJson/Internals/StringBuilder.h" #include "ArduinoJson/Internals/StringBuilder.h"

View File

@ -1,17 +1,17 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <ArduinoJson/Internals/EscapedString.h> #include <ArduinoJson/Internals/QuotedString.h>
#include <ArduinoJson/Internals/StringBuilder.h> #include <ArduinoJson/Internals/StringBuilder.h>
using namespace ArduinoJson::Internals; using namespace ArduinoJson::Internals;
class EscapedString_PrintTo_Tests : public testing::Test class QuotedString_PrintTo_Tests : public testing::Test
{ {
protected: protected:
void whenInputIs(const char* input) void whenInputIs(const char* input)
{ {
StringBuilder sb(buffer, sizeof(buffer)); StringBuilder sb(buffer, sizeof(buffer));
returnValue = EscapedString::printTo(input, &sb); returnValue = QuotedString::printTo(input, &sb);
} }
void outputMustBe(const char* expected) void outputMustBe(const char* expected)
@ -25,61 +25,61 @@ private:
size_t returnValue; size_t returnValue;
}; };
TEST_F(EscapedString_PrintTo_Tests, Null) TEST_F(QuotedString_PrintTo_Tests, Null)
{ {
whenInputIs(0); whenInputIs(0);
outputMustBe("null"); outputMustBe("null");
} }
TEST_F(EscapedString_PrintTo_Tests, EmptyString) TEST_F(QuotedString_PrintTo_Tests, EmptyString)
{ {
whenInputIs(""); whenInputIs("");
outputMustBe("\"\""); outputMustBe("\"\"");
} }
TEST_F(EscapedString_PrintTo_Tests, QuotationMark) TEST_F(QuotedString_PrintTo_Tests, QuotationMark)
{ {
whenInputIs("\""); whenInputIs("\"");
outputMustBe("\"\\\"\""); outputMustBe("\"\\\"\"");
} }
TEST_F(EscapedString_PrintTo_Tests, ReverseSolidus) TEST_F(QuotedString_PrintTo_Tests, ReverseSolidus)
{ {
whenInputIs("\\"); whenInputIs("\\");
outputMustBe("\"\\\\\""); outputMustBe("\"\\\\\"");
} }
TEST_F(EscapedString_PrintTo_Tests, Solidus) TEST_F(QuotedString_PrintTo_Tests, Solidus)
{ {
whenInputIs("/"); whenInputIs("/");
outputMustBe("\"/\""); // but the JSON format allows \/ outputMustBe("\"/\""); // but the JSON format allows \/
} }
TEST_F(EscapedString_PrintTo_Tests, Backspace) TEST_F(QuotedString_PrintTo_Tests, Backspace)
{ {
whenInputIs("\b"); whenInputIs("\b");
outputMustBe("\"\\b\""); outputMustBe("\"\\b\"");
} }
TEST_F(EscapedString_PrintTo_Tests, Formfeed) TEST_F(QuotedString_PrintTo_Tests, Formfeed)
{ {
whenInputIs("\f"); whenInputIs("\f");
outputMustBe("\"\\f\""); outputMustBe("\"\\f\"");
} }
TEST_F(EscapedString_PrintTo_Tests, Newline) TEST_F(QuotedString_PrintTo_Tests, Newline)
{ {
whenInputIs("\n"); whenInputIs("\n");
outputMustBe("\"\\n\""); outputMustBe("\"\\n\"");
} }
TEST_F(EscapedString_PrintTo_Tests, CarriageReturn) TEST_F(QuotedString_PrintTo_Tests, CarriageReturn)
{ {
whenInputIs("\r"); whenInputIs("\r");
outputMustBe("\"\\r\""); outputMustBe("\"\\r\"");
} }
TEST_F(EscapedString_PrintTo_Tests, HorizontalTab) TEST_F(QuotedString_PrintTo_Tests, HorizontalTab)
{ {
whenInputIs("\t"); whenInputIs("\t");
outputMustBe("\"\\t\""); outputMustBe("\"\\t\"");