mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-18 04:52:22 +02:00
Fixed failing test
This commit is contained in:
@ -6,6 +6,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Print.h"
|
#include "Print.h"
|
||||||
|
#include <string.h> // for strcmp
|
||||||
|
|
||||||
namespace ArduinoJson
|
namespace ArduinoJson
|
||||||
{
|
{
|
||||||
@ -21,6 +22,11 @@ namespace ArduinoJson
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
@ -33,4 +33,21 @@ size_t JsonObjectBase::printTo(Print& p) const
|
|||||||
n += p.write('}');
|
n += p.write('}');
|
||||||
|
|
||||||
return n;
|
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,22 +19,20 @@ namespace ArduinoJson
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void add(const char* key, T value)
|
void add(const char* key, T value)
|
||||||
{
|
{
|
||||||
if (count >= capacity) return;
|
KeyValuePair* pair = getMatchingPair(key);
|
||||||
|
if (!pair) return;
|
||||||
|
|
||||||
items[count].key.set(key);
|
pair->value.set(value);
|
||||||
items[count].value.set(value);
|
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<int DIGITS>
|
template<int DIGITS>
|
||||||
void add(const char* key, double value)
|
void add(const char* key, double value)
|
||||||
{
|
{
|
||||||
if (count >= capacity) return;
|
KeyValuePair* pair = getMatchingPair(key);
|
||||||
|
if (!pair) return;
|
||||||
|
|
||||||
items[count].key.set(key);
|
pair->value.set<DIGITS>(value);
|
||||||
items[count].value.set<DIGITS>(value);
|
}
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
using JsonPrintable::printTo;
|
using JsonPrintable::printTo;
|
||||||
|
|
||||||
@ -53,6 +51,8 @@ namespace ArduinoJson
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KeyValuePair* getMatchingPair(const char* key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KeyValuePair* items;
|
KeyValuePair* items;
|
||||||
int capacity, count;
|
int capacity, count;
|
||||||
|
Reference in New Issue
Block a user