forked from bblanchon/ArduinoJson
Use EscapedString for keys in JsonHashTable
This commit is contained in:
@ -10,10 +10,10 @@
|
||||
class EscapedString
|
||||
{
|
||||
public:
|
||||
EscapedString(const char* s)
|
||||
: rawString(s)
|
||||
{
|
||||
|
||||
void set(const char* s)
|
||||
{
|
||||
rawString = s;
|
||||
}
|
||||
|
||||
size_t printTo(Print&) const;
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "EscapedString.h"
|
||||
#include "JsonObjectBase.h"
|
||||
|
||||
namespace ArduinoJson
|
||||
@ -26,7 +27,7 @@ namespace ArduinoJson
|
||||
{
|
||||
if (itemCount >= N) return;
|
||||
|
||||
items[itemCount].key = key;
|
||||
items[itemCount].key.set(key);
|
||||
items[itemCount].value.set(value);
|
||||
itemCount++;
|
||||
}
|
||||
@ -36,7 +37,7 @@ namespace ArduinoJson
|
||||
{
|
||||
if (itemCount >= N) return;
|
||||
|
||||
items[itemCount].key = key;
|
||||
items[itemCount].key.set(key);
|
||||
items[itemCount].value.set<DIGITS>(value);
|
||||
itemCount++;
|
||||
}
|
||||
@ -47,7 +48,7 @@ namespace ArduinoJson
|
||||
|
||||
struct KeyValuePair
|
||||
{
|
||||
const char* key;
|
||||
EscapedString key;
|
||||
JsonValue value;
|
||||
};
|
||||
|
||||
@ -62,15 +63,12 @@ namespace ArduinoJson
|
||||
|
||||
for (int i = 0; i < itemCount; i++)
|
||||
{
|
||||
JsonValue key;
|
||||
key.set(items[i].key);
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
n += p.write(',');
|
||||
}
|
||||
|
||||
n += key.printTo(p);
|
||||
n += items[i].key.printTo(p);
|
||||
n += p.write(':');
|
||||
n += items[i].value.printTo(p);
|
||||
}
|
||||
|
@ -28,6 +28,5 @@ size_t JsonValue::printPrintableTo(const Content& c, Print& p)
|
||||
|
||||
size_t JsonValue::printStringTo(const Content& c, Print& p)
|
||||
{
|
||||
EscapedString s(c.asString);
|
||||
return s.printTo(p);
|
||||
return c.asString.printTo(p);
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "EscapedString.h"
|
||||
#include "Printable.h"
|
||||
#include "StringBuilder.h"
|
||||
|
||||
@ -43,7 +44,7 @@ namespace ArduinoJson
|
||||
void set(const char* value)
|
||||
{
|
||||
printToImpl = &printStringTo;
|
||||
content.asString = value;
|
||||
content.asString.set(value);
|
||||
}
|
||||
|
||||
template<int DIGITS=2>
|
||||
@ -65,7 +66,7 @@ namespace ArduinoJson
|
||||
bool asBool;
|
||||
long asLong;
|
||||
Printable* asPrintable;
|
||||
const char* asString;
|
||||
EscapedString asString;
|
||||
double asDouble;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user