Mer isArray() and isArrayStrict() (6796,5602)

This commit is contained in:
Benoit Blanchon
2022-03-29 12:22:05 +02:00
parent fb88d4cda0
commit 5c1fbaa43f
2 changed files with 6 additions and 13 deletions

View File

@@ -183,7 +183,7 @@ struct Converter<ArrayConstRef> {
static bool checkJson(VariantConstRef src) { static bool checkJson(VariantConstRef src) {
const VariantData* data = getData(src); const VariantData* data = getData(src);
return data && data->isArray(); return data && data->resolve()->isArray();
} }
}; };
@@ -207,7 +207,7 @@ struct Converter<ArrayRef> {
static bool checkJson(VariantRef src) { static bool checkJson(VariantRef src) {
VariantData* data = getData(src); VariantData* data = getData(src);
return data && data->isArrayStrict(); return data && data->isArray();
} }
}; };
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -90,7 +90,7 @@ class VariantData {
} }
CollectionData *asArray() { CollectionData *asArray() {
return isArrayStrict() ? &_content.asCollection : 0; return isArray() ? &_content.asCollection : 0;
} }
const CollectionData *asArray() const { const CollectionData *asArray() const {
@@ -108,13 +108,6 @@ class VariantData {
bool copyFrom(const VariantData &src, MemoryPool *pool); bool copyFrom(const VariantData &src, MemoryPool *pool);
bool isArray() const { bool isArray() const {
if (isPointer()) // P+0 G+0
return _content.asPointer->isArray();
else
return isArrayStrict();
}
bool isArrayStrict() const {
return (_flags & VALUE_IS_ARRAY) != 0; return (_flags & VALUE_IS_ARRAY) != 0;
} }
@@ -167,7 +160,7 @@ class VariantData {
} }
void remove(size_t index) { void remove(size_t index) {
if (isArrayStrict()) if (isArray())
_content.asCollection.removeElement(index); _content.asCollection.removeElement(index);
} }
@@ -285,7 +278,7 @@ class VariantData {
VariantData *addElement(MemoryPool *pool) { VariantData *addElement(MemoryPool *pool) {
if (isNull()) if (isNull())
toArray(); toArray();
if (!isArrayStrict()) if (!isArray())
return 0; return 0;
return _content.asCollection.addElement(pool); return _content.asCollection.addElement(pool);
} }
@@ -298,7 +291,7 @@ class VariantData {
VariantData *getOrAddElement(size_t index, MemoryPool *pool) { VariantData *getOrAddElement(size_t index, MemoryPool *pool) {
if (isNull()) if (isNull())
toArray(); toArray();
if (!isArrayStrict()) if (!isArray())
return 0; return 0;
return _content.asCollection.getOrAddElement(index, pool); return _content.asCollection.getOrAddElement(index, pool);
} }