From 15ad5c250e2ab8a87f3e564af482fcaf3745d78c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Mon, 12 Apr 2021 20:33:11 +0200 Subject: [PATCH] #3114: Added JSON Array::empty() method --- JSON/include/Poco/JSON/Array.h | 9 +++++++++ JSON/testsuite/src/JSONTest.cpp | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/JSON/include/Poco/JSON/Array.h b/JSON/include/Poco/JSON/Array.h index ac65b1313..32f5443df 100644 --- a/JSON/include/Poco/JSON/Array.h +++ b/JSON/include/Poco/JSON/Array.h @@ -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); diff --git a/JSON/testsuite/src/JSONTest.cpp b/JSON/testsuite/src/JSONTest.cpp index 70ec9ac1b..2d130436d 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,10 +819,12 @@ 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[0].size() == 1); + assertTrue (!da.empty()); assertTrue (da[0][0].size() == 1); assertTrue (da[0][0][0].size() == 0); }