Fixes to JSON library.

This commit is contained in:
Thulinma 2015-10-09 15:00:03 +02:00
parent 67dc1848e7
commit 1eb5725751

View file

@ -427,7 +427,9 @@ JSON::Value::Value(bool val) {
/// Compares a JSON::Value to another for equality. /// Compares a JSON::Value to another for equality.
bool JSON::Value::operator==(const JSON::Value & rhs) const { bool JSON::Value::operator==(const JSON::Value & rhs) const {
if (myType != rhs.myType) return false; if (myType != rhs.myType){
return false;
}
if (myType == INTEGER || myType == BOOL) { if (myType == INTEGER || myType == BOOL) {
return intVal == rhs.intVal; return intVal == rhs.intVal;
} }
@ -437,26 +439,22 @@ bool JSON::Value::operator==(const JSON::Value & rhs) const {
if (myType == EMPTY) { if (myType == EMPTY) {
return true; return true;
} }
if (size() != rhs.size()){
return false;
}
if (myType == OBJECT) { if (myType == OBJECT) {
if (objVal.size() != rhs.objVal.size()) return false; jsonForEachConst(*this, it){
for (std::map<std::string, Value*>::const_iterator it = objVal.begin(); it != objVal.end(); ++it) { if (!rhs.isMember(it.key()) || *it != rhs[it.key()]) {
if (!rhs.isMember(it->first)) {
return false;
}
if (*(it->second) != rhs.objVal.find(it->first)->second) {
return false; return false;
} }
} }
return true; return true;
} }
if (myType == ARRAY) { if (myType == ARRAY) {
if (arrVal.size() != rhs.arrVal.size()) return false; jsonForEachConst(*this, it){
int i = 0; if (*it != rhs[it.num()]) {
for (std::deque<Value*>::const_iterator it = arrVal.begin(); it != arrVal.end(); ++it) {
if (**it != *(rhs.arrVal[i])) {
return false; return false;
} }
i++;
} }
return true; return true;
} }