JSON compareExcept and compareOnly functions now support arrays.
This commit is contained in:
		
							parent
							
								
									075756d646
								
							
						
					
					
						commit
						7b0da7b65c
					
				
					 1 changed files with 36 additions and 22 deletions
				
			
		
							
								
								
									
										26
									
								
								lib/json.cpp
									
										
									
									
									
								
							
							
						
						
									
										26
									
								
								lib/json.cpp
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -607,9 +607,7 @@ bool JSON::Value::operator!=(const JSON::Value & rhs) const {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
bool JSON::Value::compareExcept(const Value & rhs, const std::set<std::string> & skip) const {
 | 
			
		||||
  if (myType != OBJECT) {
 | 
			
		||||
    return ((*this) == rhs);
 | 
			
		||||
  }
 | 
			
		||||
  if (myType == OBJECT) {
 | 
			
		||||
    jsonForEachConst(*this, it){
 | 
			
		||||
      if (skip.count(it.key())){continue;}
 | 
			
		||||
      if (!rhs.isMember(it.key()) || !(*it).compareExcept(rhs[it.key()], skip)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -621,12 +619,19 @@ bool JSON::Value::compareExcept(const Value & rhs, const std::set<std::string> &
 | 
			
		|||
      if (!(*this).isMember(it.key())){return false;}
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
  if (myType == ARRAY) {
 | 
			
		||||
    if (size() != rhs.size()){return false;}
 | 
			
		||||
    jsonForEachConst(*this, it){
 | 
			
		||||
      if (!(*it).compareExcept(rhs[it.num()], skip)){return false;}
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
  return ((*this) == rhs);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool JSON::Value::compareOnly(const Value & rhs, const std::set<std::string> & check) const {
 | 
			
		||||
  if (myType != OBJECT) {
 | 
			
		||||
    return ((*this) == rhs);
 | 
			
		||||
  }
 | 
			
		||||
  if (myType == OBJECT) {
 | 
			
		||||
    jsonForEachConst(*this, it){
 | 
			
		||||
      if (!check.count(it.key())){continue;}
 | 
			
		||||
      if (!rhs.isMember(it.key()) || !(*it).compareOnly(rhs[it.key()], check)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -638,6 +643,15 @@ bool JSON::Value::compareOnly(const Value & rhs, const std::set<std::string> & c
 | 
			
		|||
      if (!(*this).isMember(it.key())){return false;}
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
  if (myType == ARRAY) {
 | 
			
		||||
    if (size() != rhs.size()){return false;}
 | 
			
		||||
    jsonForEachConst(*this, it){
 | 
			
		||||
      if (!(*it).compareOnly(rhs[it.num()], check)){return false;}
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
  return ((*this) == rhs);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Completely clears the contents of this value,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue