Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added JSON Array::empty() method #3114

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions JSON/include/Poco/JSON/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions JSON/testsuite/src/JSONTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}


Expand All @@ -817,9 +819,11 @@ 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.empty());
assertTrue (da[0].size() == 1);
assertTrue (da[0][0].size() == 1);
assertTrue (da[0][0][0].size() == 0);
Expand Down