Combine objectDependices and objectRequired into propertyExist array
This commit is contained in:
parent
f586edd33d
commit
a6571d504a
@ -289,8 +289,7 @@ struct SchemaValidationContext {
|
|||||||
patternPropertiesSchemas(),
|
patternPropertiesSchemas(),
|
||||||
patternPropertiesSchemaCount(),
|
patternPropertiesSchemaCount(),
|
||||||
valuePatternValidatorType(kPatternValidatorOnly),
|
valuePatternValidatorType(kPatternValidatorOnly),
|
||||||
objectDependencies(),
|
propertyExist(),
|
||||||
objectRequired(),
|
|
||||||
inArray(false),
|
inArray(false),
|
||||||
valueUniqueness(false),
|
valueUniqueness(false),
|
||||||
arrayUniqueness(false)
|
arrayUniqueness(false)
|
||||||
@ -312,10 +311,8 @@ struct SchemaValidationContext {
|
|||||||
}
|
}
|
||||||
if (patternPropertiesSchemas)
|
if (patternPropertiesSchemas)
|
||||||
factory.FreeState(patternPropertiesSchemas);
|
factory.FreeState(patternPropertiesSchemas);
|
||||||
if (objectDependencies)
|
if (propertyExist)
|
||||||
factory.FreeState(objectDependencies);
|
factory.FreeState(propertyExist);
|
||||||
if (objectRequired)
|
|
||||||
factory.FreeState(objectRequired);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SchemaValidatorFactoryType& factory;
|
SchemaValidatorFactoryType& factory;
|
||||||
@ -333,8 +330,7 @@ struct SchemaValidationContext {
|
|||||||
PatternValidatorType valuePatternValidatorType;
|
PatternValidatorType valuePatternValidatorType;
|
||||||
PatternValidatorType objectPatternValidatorType;
|
PatternValidatorType objectPatternValidatorType;
|
||||||
SizeType arrayElementIndex;
|
SizeType arrayElementIndex;
|
||||||
bool* objectDependencies;
|
bool* propertyExist;
|
||||||
bool* objectRequired;
|
|
||||||
bool inArray;
|
bool inArray;
|
||||||
bool valueUniqueness;
|
bool valueUniqueness;
|
||||||
bool arrayUniqueness;
|
bool arrayUniqueness;
|
||||||
@ -770,14 +766,9 @@ public:
|
|||||||
if (!(type_ & (1 << kObjectSchemaType)))
|
if (!(type_ & (1 << kObjectSchemaType)))
|
||||||
RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
|
RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
|
||||||
|
|
||||||
if (hasRequired_) {
|
if (hasDependencies_ || hasRequired_) {
|
||||||
context.objectRequired = static_cast<bool*>(context.factory.MallocState(sizeof(bool) * propertyCount_));
|
context.propertyExist = static_cast<bool*>(context.factory.MallocState(sizeof(bool) * propertyCount_));
|
||||||
std::memset(context.objectRequired, 0, sizeof(bool) * propertyCount_);
|
std::memset(context.propertyExist, 0, sizeof(bool) * propertyCount_);
|
||||||
}
|
|
||||||
|
|
||||||
if (hasDependencies_) {
|
|
||||||
context.objectDependencies = static_cast<bool*>(context.factory.MallocState(sizeof(bool) * propertyCount_));
|
|
||||||
std::memset(context.objectDependencies, 0, sizeof(bool) * propertyCount_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (patternProperties_) { // pre-allocate schema array
|
if (patternProperties_) { // pre-allocate schema array
|
||||||
@ -808,11 +799,8 @@ public:
|
|||||||
else
|
else
|
||||||
context.valueSchema = properties_[index].schema;
|
context.valueSchema = properties_[index].schema;
|
||||||
|
|
||||||
if (hasRequired_)
|
if (context.propertyExist)
|
||||||
context.objectRequired[index] = true;
|
context.propertyExist[index] = true;
|
||||||
|
|
||||||
if (hasDependencies_)
|
|
||||||
context.objectDependencies[index] = true;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -840,11 +828,10 @@ public:
|
|||||||
|
|
||||||
bool EndObject(Context& context, SizeType memberCount) const {
|
bool EndObject(Context& context, SizeType memberCount) const {
|
||||||
if (hasRequired_)
|
if (hasRequired_)
|
||||||
for (SizeType index = 0; index < propertyCount_; index++) {
|
for (SizeType index = 0; index < propertyCount_; index++)
|
||||||
if (properties_[index].required)
|
if (properties_[index].required)
|
||||||
if (!context.objectRequired[index])
|
if (!context.propertyExist[index])
|
||||||
RAPIDJSON_INVALID_KEYWORD_RETURN(GetRequiredString());
|
RAPIDJSON_INVALID_KEYWORD_RETURN(GetRequiredString());
|
||||||
}
|
|
||||||
|
|
||||||
if (memberCount < minProperties_)
|
if (memberCount < minProperties_)
|
||||||
RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinPropertiesString());
|
RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinPropertiesString());
|
||||||
@ -854,10 +841,10 @@ public:
|
|||||||
|
|
||||||
if (hasDependencies_) {
|
if (hasDependencies_) {
|
||||||
for (SizeType sourceIndex = 0; sourceIndex < propertyCount_; sourceIndex++)
|
for (SizeType sourceIndex = 0; sourceIndex < propertyCount_; sourceIndex++)
|
||||||
if (context.objectDependencies[sourceIndex]) {
|
if (context.propertyExist[sourceIndex]) {
|
||||||
if (properties_[sourceIndex].dependencies) {
|
if (properties_[sourceIndex].dependencies) {
|
||||||
for (SizeType targetIndex = 0; targetIndex < propertyCount_; targetIndex++)
|
for (SizeType targetIndex = 0; targetIndex < propertyCount_; targetIndex++)
|
||||||
if (properties_[sourceIndex].dependencies[targetIndex] && !context.objectDependencies[targetIndex])
|
if (properties_[sourceIndex].dependencies[targetIndex] && !context.propertyExist[targetIndex])
|
||||||
RAPIDJSON_INVALID_KEYWORD_RETURN(GetDependenciesString());
|
RAPIDJSON_INVALID_KEYWORD_RETURN(GetDependenciesString());
|
||||||
}
|
}
|
||||||
else if (properties_[sourceIndex].dependenciesSchema)
|
else if (properties_[sourceIndex].dependenciesSchema)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user