mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-18 04:52:22 +02:00
Reduced usages of EscapedString
This commit is contained in:
@ -6,7 +6,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Print.h"
|
#include "Print.h"
|
||||||
#include <string.h> // for strcmp
|
|
||||||
|
|
||||||
namespace ArduinoJson
|
namespace ArduinoJson
|
||||||
{
|
{
|
||||||
@ -16,18 +15,13 @@ namespace ArduinoJson
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void set(const char* s)
|
EscapedString(const char* s)
|
||||||
{
|
: rawString(s)
|
||||||
rawString = s;
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t printTo(Print&) const;
|
size_t printTo(Print&) const;
|
||||||
|
|
||||||
bool equals(char const* s)
|
|
||||||
{
|
|
||||||
return strcmp(s, rawString) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char* rawString;
|
const char* rawString;
|
||||||
};
|
};
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "JsonObjectBase.h"
|
#include "JsonObjectBase.h"
|
||||||
|
#include <string.h> // for strcmp
|
||||||
|
|
||||||
using namespace ArduinoJson::Generator;
|
using namespace ArduinoJson::Generator;
|
||||||
using namespace ArduinoJson::Internals;
|
using namespace ArduinoJson::Internals;
|
||||||
@ -19,7 +20,7 @@ size_t JsonObjectBase::printTo(Print& p) const
|
|||||||
const KeyValuePair* current = items;
|
const KeyValuePair* current = items;
|
||||||
for (int i = count; i > 0; i--)
|
for (int i = count; i > 0; i--)
|
||||||
{
|
{
|
||||||
n += current->key.printTo(p);
|
n += EscapedString(current->key).printTo(p);
|
||||||
n += p.write(':');
|
n += p.write(':');
|
||||||
n += current->value.printTo(p);
|
n += current->value.printTo(p);
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ JsonValue& JsonObjectBase::operator[](char const* key)
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < count; ++i)
|
for (int i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
if (items[i].key.equals(key))
|
if (!strcmp(items[i].key, key))
|
||||||
{
|
{
|
||||||
return items[i].value;
|
return items[i].value;
|
||||||
}
|
}
|
||||||
@ -49,6 +50,6 @@ JsonValue& JsonObjectBase::operator[](char const* key)
|
|||||||
if (count >= capacity)
|
if (count >= capacity)
|
||||||
return JsonValue::null();
|
return JsonValue::null();
|
||||||
|
|
||||||
items[count].key.set(key);
|
items[count].key = key;
|
||||||
return items[count++].value;
|
return items[count++].value;
|
||||||
}
|
}
|
@ -38,8 +38,8 @@ namespace ArduinoJson
|
|||||||
|
|
||||||
struct KeyValuePair
|
struct KeyValuePair
|
||||||
{
|
{
|
||||||
Internals::EscapedString key;
|
const char* key;
|
||||||
JsonValue value;
|
JsonValue value;
|
||||||
};
|
};
|
||||||
|
|
||||||
JsonObjectBase(KeyValuePair* items, int capacity)
|
JsonObjectBase(KeyValuePair* items, int capacity)
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "JsonValue.h"
|
#include "JsonValue.h"
|
||||||
|
|
||||||
using namespace ArduinoJson::Generator;
|
using namespace ArduinoJson::Generator;
|
||||||
|
using namespace ArduinoJson::Internals;
|
||||||
|
|
||||||
JsonValue JsonValue::nullInstance;
|
JsonValue JsonValue::nullInstance;
|
||||||
|
|
||||||
@ -30,5 +31,5 @@ size_t JsonValue::printPrintableTo(const Content& c, Print& p)
|
|||||||
|
|
||||||
size_t JsonValue::printStringTo(const Content& c, Print& p)
|
size_t JsonValue::printStringTo(const Content& c, Print& p)
|
||||||
{
|
{
|
||||||
return c.asString.printTo(p);
|
return EscapedString(c.asString).printTo(p);
|
||||||
}
|
}
|
@ -44,7 +44,7 @@ namespace ArduinoJson
|
|||||||
void operator=(const char* value)
|
void operator=(const char* value)
|
||||||
{
|
{
|
||||||
printToImpl = &printStringTo;
|
printToImpl = &printStringTo;
|
||||||
content.asString.set(value);
|
content.asString = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator=(double value)
|
void operator=(double value)
|
||||||
@ -108,11 +108,11 @@ namespace ArduinoJson
|
|||||||
private:
|
private:
|
||||||
union Content
|
union Content
|
||||||
{
|
{
|
||||||
bool asBool;
|
bool asBool;
|
||||||
long asLong;
|
double asDouble;
|
||||||
Printable* asPrintable;
|
long asLong;
|
||||||
Internals::EscapedString asString;
|
Printable* asPrintable;
|
||||||
double asDouble;
|
const char* asString;
|
||||||
};
|
};
|
||||||
|
|
||||||
Content content;
|
Content content;
|
||||||
|
@ -16,8 +16,7 @@ namespace JsonGeneratorTests
|
|||||||
{
|
{
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
size_t returnValue;
|
size_t returnValue;
|
||||||
EscapedString escapedString;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TEST_METHOD(Null)
|
TEST_METHOD(Null)
|
||||||
@ -83,8 +82,8 @@ namespace JsonGeneratorTests
|
|||||||
private:
|
private:
|
||||||
void whenInputIs(const char* input)
|
void whenInputIs(const char* input)
|
||||||
{
|
{
|
||||||
StringBuilder sb(buffer, sizeof(buffer));
|
StringBuilder sb(buffer, sizeof(buffer));
|
||||||
escapedString.set(input);
|
EscapedString escapedString = input;
|
||||||
returnValue = escapedString.printTo(sb);
|
returnValue = escapedString.printTo(sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user