mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-18 04:52:22 +02:00
Removed JsonValue::null(), moved the instance to JsonObjectBase
This commit is contained in:
@ -9,6 +9,10 @@
|
||||
using namespace ArduinoJson::Generator;
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
|
||||
JsonValue JsonObjectBase::nullValue;
|
||||
|
||||
|
||||
size_t JsonObjectBase::printTo(Print& p) const
|
||||
{
|
||||
size_t n = 0;
|
||||
@ -51,10 +55,19 @@ JsonValue& JsonObjectBase::operator[](char const* key)
|
||||
p++;
|
||||
}
|
||||
|
||||
if (count >= capacity)
|
||||
return JsonValue::null();
|
||||
JsonValue* value;
|
||||
|
||||
if (count < capacity)
|
||||
{
|
||||
count++;
|
||||
p->key = key;
|
||||
return p->value;
|
||||
value = &p->value;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = &nullValue;
|
||||
}
|
||||
|
||||
value->reset();
|
||||
return *value;
|
||||
}
|
@ -50,6 +50,8 @@ namespace ArduinoJson
|
||||
private:
|
||||
KeyValuePair* items;
|
||||
int capacity, count;
|
||||
|
||||
static JsonValue nullValue;
|
||||
};
|
||||
}
|
||||
}
|
@ -9,8 +9,6 @@
|
||||
using namespace ArduinoJson::Generator;
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
JsonValue JsonValue::nullInstance;
|
||||
|
||||
size_t JsonValue::printBoolTo(const Content& c, Print& p)
|
||||
{
|
||||
return p.print(c.asBool ? "true" : "false");
|
||||
|
@ -100,9 +100,10 @@ namespace ArduinoJson
|
||||
return printToImpl(content, p);
|
||||
}
|
||||
|
||||
static JsonValue& null()
|
||||
void reset()
|
||||
{
|
||||
return nullInstance;
|
||||
content.asDouble = 0;
|
||||
printToImpl = printStringTo;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -129,8 +130,6 @@ namespace ArduinoJson
|
||||
{
|
||||
return p.print(c.asDouble, DIGITS);
|
||||
}
|
||||
|
||||
static JsonValue nullInstance;
|
||||
};
|
||||
}
|
||||
}
|
@ -18,10 +18,10 @@ namespace JsonGeneratorTests
|
||||
|
||||
public:
|
||||
|
||||
/* TEST_METHOD(Empty)
|
||||
TEST_METHOD(Empty)
|
||||
{
|
||||
mustNotContain("key");
|
||||
}*/
|
||||
}
|
||||
|
||||
TEST_METHOD(OneString)
|
||||
{
|
||||
@ -35,8 +35,14 @@ namespace JsonGeneratorTests
|
||||
|
||||
void mustContain(const char* key, const char* expected)
|
||||
{
|
||||
auto actual = (const char*) object[key];
|
||||
const char* actual = object[key];
|
||||
Assert::AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
void mustNotContain(const char* key)
|
||||
{
|
||||
const char* actual = object[key];
|
||||
Assert::IsNull(actual);
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user