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