#3114: Added JSON Array::empty() method

This commit is contained in:
Günter Obiltschnig 2021-04-12 20:33:11 +02:00
parent eb992c9042
commit 95214e428a
2 changed files with 13 additions and 0 deletions

View File

@ -124,6 +124,9 @@ public:
std::size_t size() const;
/// Returns the size of the array.
bool empty() const;
/// Returns true if the array is empty, false otherwise.
bool isArray(unsigned int index) const;
/// Returns true when the element is an array.
@ -241,6 +244,12 @@ inline std::size_t Array::size() const
}
inline bool Array::empty() const
{
return _values.empty();
}
inline bool Array::isArray(unsigned int index) const
{
Dynamic::Var value = get(index);

View File

@ -791,9 +791,11 @@ void JSONTest::testEmptyArray()
Poco::JSON::Array::Ptr array = result.extract<Poco::JSON::Array::Ptr>();
assertTrue (array->size() == 0);
assertTrue (array->empty());
Poco::Dynamic::Array da = *array;
assertTrue (da.size() == 0);
assertTrue (da.empty());
}
@ -817,10 +819,12 @@ void JSONTest::testNestedArray()
Poco::JSON::Array::Ptr array = result.extract<Poco::JSON::Array::Ptr>();
assertTrue (array->size() == 1);
assertTrue (!array->empty());
Poco::Dynamic::Array da = *array;
assertTrue (da.size() == 1);
assertTrue (da[0].size() == 1);
assertTrue (!da.empty());
assertTrue (da[0][0].size() == 1);
assertTrue (da[0][0][0].size() == 0);
}