Commit 09530ad8 authored by miloyip's avatar miloyip

Fix compilation

parent 490630b7
...@@ -93,10 +93,13 @@ enum PatternValidatorType { ...@@ -93,10 +93,13 @@ enum PatternValidatorType {
template <typename Encoding> template <typename Encoding>
struct SchemaValidationContext { struct SchemaValidationContext {
SchemaValidationContext(const BaseSchema<Encoding>* s) : SchemaValidationContext(const BaseSchema<Encoding>* s) :
schema(s), valueSchema(), notValidator(), objectDependencies(), schema(s),
valueSchema(),
patternPropertiesSchemas(), patternPropertiesSchemas(),
notValidator(),
patternPropertiesSchemaCount(), patternPropertiesSchemaCount(),
valuePatternValidatorType(kPatternValidatorOnly), valuePatternValidatorType(kPatternValidatorOnly),
objectDependencies(),
inArray(false) inArray(false)
{ {
} }
...@@ -115,10 +118,10 @@ struct SchemaValidationContext { ...@@ -115,10 +118,10 @@ struct SchemaValidationContext {
SchemaValidatorArray<Encoding> dependencyValidators; SchemaValidatorArray<Encoding> dependencyValidators;
SchemaValidatorArray<Encoding> patternPropertiesValidators; SchemaValidatorArray<Encoding> patternPropertiesValidators;
const BaseSchema<Encoding>** patternPropertiesSchemas; const BaseSchema<Encoding>** patternPropertiesSchemas;
GenericSchemaValidator<Encoding, BaseReaderHandler<>, CrtAllocator>* notValidator;
SizeType patternPropertiesSchemaCount; SizeType patternPropertiesSchemaCount;
PatternValidatorType valuePatternValidatorType; PatternValidatorType valuePatternValidatorType;
PatternValidatorType objectPatternValidatorType; PatternValidatorType objectPatternValidatorType;
GenericSchemaValidator<Encoding, BaseReaderHandler<>, CrtAllocator>* notValidator;
SizeType objectRequiredCount; SizeType objectRequiredCount;
SizeType arrayElementIndex; SizeType arrayElementIndex;
bool* objectDependencies; bool* objectDependencies;
...@@ -612,6 +615,12 @@ public: ...@@ -612,6 +615,12 @@ public:
} }
private: private:
#if RAPIDJSON_SCHEMA_USE_STDREGEX
typedef std::basic_regex<Ch>* RegexType;
#else
typedef char RegexType;
#endif
typedef GenericSchemaValidator<Encoding, BaseReaderHandler<>, CrtAllocator> SchemaValidatorType; typedef GenericSchemaValidator<Encoding, BaseReaderHandler<>, CrtAllocator> SchemaValidatorType;
static const BaseSchema<Encoding>* GetTypeless() { static const BaseSchema<Encoding>* GetTypeless() {
static BaseSchema<Encoding> typeless(Value(kObjectType).Move()); static BaseSchema<Encoding> typeless(Value(kObjectType).Move());
...@@ -661,25 +670,25 @@ private: ...@@ -661,25 +670,25 @@ private:
#if RAPIDJSON_SCHEMA_USE_STDREGEX #if RAPIDJSON_SCHEMA_USE_STDREGEX
template <typename ValueType> template <typename ValueType>
static std::basic_regex<Ch>* CreatePattern(const ValueType& value) { static RegexType* CreatePattern(const ValueType& value) {
if (value.IsString()) if (value.IsString())
try { try {
return new std::basic_regex<Ch>(value.GetString(), std::size_t(value.GetStringLength()), std::regex_constants::ECMAScript); return new RegexType(value.GetString(), std::size_t(value.GetStringLength()), std::regex_constants::ECMAScript);
} }
catch (const std::regex_error&) { catch (const std::regex_error&) {
} }
return 0; return 0;
} }
static bool IsPatternMatch(const std::basic_regex<Ch>* pattern, const Ch *str, SizeType length) { static bool IsPatternMatch(const RegexType* pattern, const Ch *str, SizeType length) {
std::match_results<const Ch*> r; std::match_results<const Ch*> r;
return std::regex_search(str, str + length, r, *pattern); return std::regex_search(str, str + length, r, *pattern);
} }
#else #else
template <typename ValueType> template <typename ValueType>
void* CreatePattern(const ValueType&) { return 0; } RegexType* CreatePattern(const ValueType&) { return 0; }
static bool IsPatternMatch(const void*, const Ch *, SizeType) { return true; } static bool IsPatternMatch(const RegexType*, const Ch *, SizeType) { return true; }
#endif // RAPIDJSON_SCHEMA_USE_STDREGEX #endif // RAPIDJSON_SCHEMA_USE_STDREGEX
void AddType(const Value& type) { void AddType(const Value& type) {
...@@ -781,11 +790,7 @@ private: ...@@ -781,11 +790,7 @@ private:
} }
BaseSchema<Encoding>* schema; BaseSchema<Encoding>* schema;
#if RAPIDJSON_SCHEMA_USE_STDREGEX RegexType* pattern;
std::basic_regex<Ch>* pattern;
#else
void *pattern;
#endif
}; };
MemoryPoolAllocator<> allocator_; MemoryPoolAllocator<> allocator_;
...@@ -816,11 +821,7 @@ private: ...@@ -816,11 +821,7 @@ private:
SizeType maxItems_; SizeType maxItems_;
bool additionalItems_; bool additionalItems_;
#if RAPIDJSON_SCHEMA_USE_STDREGEX RegexType* pattern_;
std::basic_regex<Ch>* pattern_;
#else
void* pattern_;
#endif
SizeType minLength_; SizeType minLength_;
SizeType maxLength_; SizeType maxLength_;
......
...@@ -149,6 +149,7 @@ TEST(SchemaValidator, String_LengthRange) { ...@@ -149,6 +149,7 @@ TEST(SchemaValidator, String_LengthRange) {
VALIDATE(s, "\"ABCD\"", false); VALIDATE(s, "\"ABCD\"", false);
} }
#if RAPIDJSON_SCHEMA_HAS_REGEX
TEST(SchemaValidator, String_Pattern) { TEST(SchemaValidator, String_Pattern) {
Document sd; Document sd;
sd.Parse("{\"type\":\"string\",\"pattern\":\"^(\\\\([0-9]{3}\\\\))?[0-9]{3}-[0-9]{4}$\"}"); sd.Parse("{\"type\":\"string\",\"pattern\":\"^(\\\\([0-9]{3}\\\\))?[0-9]{3}-[0-9]{4}$\"}");
...@@ -159,6 +160,7 @@ TEST(SchemaValidator, String_Pattern) { ...@@ -159,6 +160,7 @@ TEST(SchemaValidator, String_Pattern) {
VALIDATE(s, "\"(888)555-1212 ext. 532\"", false); VALIDATE(s, "\"(888)555-1212 ext. 532\"", false);
VALIDATE(s, "\"(800)FLOWERS\"", false); VALIDATE(s, "\"(800)FLOWERS\"", false);
} }
#endif
TEST(SchemaValidator, Integer) { TEST(SchemaValidator, Integer) {
Document sd; Document sd;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment