1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-23 00:28:08 +02:00

replaced JsonNode::isEmpty() with JsonNode::containsBaseData()

This commit is contained in:
Henning Koehler
2017-09-16 10:23:31 +12:00
parent 6414cd18e8
commit ee46862784
3 changed files with 17 additions and 13 deletions

View File

@ -214,21 +214,22 @@ bool JsonNode::isNumber() const
return type == JsonType::DATA_INTEGER || type == JsonType::DATA_FLOAT;
}
bool JsonNode::isEmpty() const
bool JsonNode::containsBaseData() const
{
switch(type)
{
case JsonType::DATA_NULL:
return true;
return false;
case JsonType::DATA_STRUCT:
for(auto elem : *data.Struct)
{
if(!elem.second.isEmpty())
return false;
if(elem.second.containsBaseData())
return true;
}
return true;
default:
return false;
default:
//other types (including vector) cannot be extended via merge
return true;
}
}
@ -908,7 +909,7 @@ JsonNode JsonUtils::intersect(const JsonNode & a, const JsonNode & b, bool prune
if(vstd::contains(b.Struct(), property.first))
{
JsonNode propertyIntersect = JsonUtils::intersect(property.second, b.Struct().find(property.first)->second);
if(pruneEmpty && propertyIntersect.isEmpty())
if(pruneEmpty && !propertyIntersect.containsBaseData())
continue;
result[property.first] = propertyIntersect;
}
@ -934,16 +935,17 @@ JsonNode JsonUtils::difference(const JsonNode & node, const JsonNode & base)
{
if(vstd::contains(base.Struct(), property.first))
{
JsonNode propertyDifference = JsonUtils::difference(property.second, base.Struct().find(property.first)->second);
if(propertyDifference.isEmpty())
continue;
result[property.first] = propertyDifference;
const JsonNode propertyDifference = JsonUtils::difference(property.second, base.Struct().find(property.first)->second);
if(!propertyDifference.isNull())
result[property.first] = propertyDifference;
}
else
{
result[property.first] = property.second;
}
}
if(result.Struct().empty())
return nullNode;
return result;
}
else