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
{
class EscapedString
class QuotedString
{
public:
static size_t printTo(const char*, Print*);

View File

@ -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;

View File

@ -4,7 +4,7 @@
#include <ctype.h>
#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);
}

View File

@ -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)

View File

@ -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"

View File

@ -1,17 +1,17 @@
#include <gtest/gtest.h>
#include <ArduinoJson/Internals/EscapedString.h>
#include <ArduinoJson/Internals/QuotedString.h>
#include <ArduinoJson/Internals/StringBuilder.h>
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\"");