diff --git a/JSON/include/Poco/JSON/Array.h b/JSON/include/Poco/JSON/Array.h index ac65b1313d..a58e6e46d1 100644 --- a/JSON/include/Poco/JSON/Array.h +++ b/JSON/include/Poco/JSON/Array.h @@ -124,6 +124,9 @@ class JSON_API Array 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); diff --git a/JSON/testsuite/src/JSONTest.cpp b/JSON/testsuite/src/JSONTest.cpp index c34626711a..4b3f3d6e53 100644 --- a/JSON/testsuite/src/JSONTest.cpp +++ b/JSON/testsuite/src/JSONTest.cpp @@ -791,9 +791,11 @@ void JSONTest::testEmptyArray() Poco::JSON::Array::Ptr array = result.extract(); assertTrue (array->size() == 0); + assertTrue (array->empty()); Poco::Dynamic::Array da = *array; assertTrue (da.size() == 0); + assertTrue (da.empty()); } @@ -817,9 +819,11 @@ void JSONTest::testNestedArray() Poco::JSON::Array::Ptr array = result.extract(); assertTrue (array->size() == 1); + assertTrue (!array->empty()); Poco::Dynamic::Array da = *array; assertTrue (da.size() == 1); + assertTrue (!da.empty()); assertTrue (da[0].size() == 1); assertTrue (da[0][0].size() == 1); assertTrue (da[0][0][0].size() == 0);