forked from bblanchon/ArduinoJson
Fixed failing test
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Print.h"
|
||||
#include <string.h> // for strcmp
|
||||
|
||||
namespace ArduinoJson
|
||||
{
|
||||
@ -22,6 +23,11 @@ namespace ArduinoJson
|
||||
|
||||
size_t printTo(Print&) const;
|
||||
|
||||
bool equals(char const* s)
|
||||
{
|
||||
return strcmp(s, rawString) == 0;
|
||||
}
|
||||
|
||||
private:
|
||||
const char* rawString;
|
||||
};
|
||||
|
@ -34,3 +34,20 @@ size_t JsonObjectBase::printTo(Print& p) const
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
JsonObjectBase::KeyValuePair* JsonObjectBase::getMatchingPair(char const* key)
|
||||
{
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
if (items[i].key.equals(key))
|
||||
{
|
||||
return &items[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (count >= capacity) return 0;
|
||||
|
||||
KeyValuePair* p = &items[count++];
|
||||
p->key.set(key);
|
||||
return p;
|
||||
}
|
@ -19,21 +19,19 @@ namespace ArduinoJson
|
||||
template<typename T>
|
||||
void add(const char* key, T value)
|
||||
{
|
||||
if (count >= capacity) return;
|
||||
KeyValuePair* pair = getMatchingPair(key);
|
||||
if (!pair) return;
|
||||
|
||||
items[count].key.set(key);
|
||||
items[count].value.set(value);
|
||||
count++;
|
||||
pair->value.set(value);
|
||||
}
|
||||
|
||||
template<int DIGITS>
|
||||
void add(const char* key, double value)
|
||||
{
|
||||
if (count >= capacity) return;
|
||||
KeyValuePair* pair = getMatchingPair(key);
|
||||
if (!pair) return;
|
||||
|
||||
items[count].key.set(key);
|
||||
items[count].value.set<DIGITS>(value);
|
||||
count++;
|
||||
pair->value.set<DIGITS>(value);
|
||||
}
|
||||
|
||||
using JsonPrintable::printTo;
|
||||
@ -53,6 +51,8 @@ namespace ArduinoJson
|
||||
{
|
||||
}
|
||||
|
||||
KeyValuePair* getMatchingPair(const char* key);
|
||||
|
||||
private:
|
||||
KeyValuePair* items;
|
||||
int capacity, count;
|
||||
|
Reference in New Issue
Block a user