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