Commit d4d03cab authored by Milo Yip's avatar Milo Yip

Use internal regex as default in schema validator

parent b8d2f7e6
...@@ -65,8 +65,8 @@ public: ...@@ -65,8 +65,8 @@ public:
typedef typename Encoding::Ch Ch; typedef typename Encoding::Ch Ch;
GenericRegex(const Ch* source, Allocator* allocator = 0) : states_(allocator, 256), ranges_(allocator, 256), root_(kRegexInvalidState), stateCount_(), rangeCount_(), anchorBegin_(), anchorEnd_() { GenericRegex(const Ch* source, Allocator* allocator = 0) : states_(allocator, 256), ranges_(allocator, 256), root_(kRegexInvalidState), stateCount_(), rangeCount_(), anchorBegin_(), anchorEnd_() {
StringStream ss(source); GenericStringStream<Encoding> ss(source);
DecodedStream<StringStream> ds(ss); DecodedStream<GenericStringStream<Encoding> > ds(ss);
Parse(ds); Parse(ds);
} }
...@@ -83,7 +83,7 @@ public: ...@@ -83,7 +83,7 @@ public:
} }
bool Match(const Ch* s) const { bool Match(const Ch* s) const {
StringStream is(s); GenericStringStream<Encoding> is(s);
return Match(is); return Match(is);
} }
...@@ -93,7 +93,7 @@ public: ...@@ -93,7 +93,7 @@ public:
} }
bool Search(const Ch* s) const { bool Search(const Ch* s) const {
StringStream is(s); GenericStringStream<Encoding> is(s);
return Search(is); return Search(is);
} }
......
...@@ -19,17 +19,25 @@ ...@@ -19,17 +19,25 @@
#include "pointer.h" #include "pointer.h"
#include <cmath> // HUGE_VAL, abs, floor #include <cmath> // HUGE_VAL, abs, floor
#if !defined(RAPIDJSON_SCHEMA_USE_STDREGEX) && (__cplusplus >=201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)) #if !defined(RAPIDJSON_SCHEMA_USE_INTERNALREGEX)
#define RAPIDJSON_SCHEMA_USE_INTERNALREGEX 1
#else
#define RAPIDJSON_SCHEMA_USE_INTERNALREGEX 0
#endif
#if !RAPIDJSON_SCHEMA_USE_INTERNALREGEX && !defined(RAPIDJSON_SCHEMA_USE_STDREGEX) && (__cplusplus >=201103L || (defined(_MSC_VER) && _MSC_VER >= 1800))
#define RAPIDJSON_SCHEMA_USE_STDREGEX 1 #define RAPIDJSON_SCHEMA_USE_STDREGEX 1
#else #else
#define RAPIDJSON_SCHEMA_USE_STDREGEX 0 #define RAPIDJSON_SCHEMA_USE_STDREGEX 0
#endif #endif
#if RAPIDJSON_SCHEMA_USE_STDREGEX #if RAPIDJSON_SCHEMA_USE_INTERNALREGEX
#include "internal/regex.h"
#elif RAPIDJSON_SCHEMA_USE_STDREGEX
#include <regex> #include <regex>
#endif #endif
#if RAPIDJSON_SCHEMA_USE_STDREGEX #if RAPIDJSON_SCHEMA_USE_INTERNALREGEX || RAPIDJSON_SCHEMA_USE_STDREGEX
#define RAPIDJSON_SCHEMA_HAS_REGEX 1 #define RAPIDJSON_SCHEMA_HAS_REGEX 1
#else #else
#define RAPIDJSON_SCHEMA_HAS_REGEX 0 #define RAPIDJSON_SCHEMA_HAS_REGEX 0
...@@ -560,7 +568,7 @@ public: ...@@ -560,7 +568,7 @@ public:
AllocatorType::Free(patternProperties_); AllocatorType::Free(patternProperties_);
} }
AllocatorType::Free(itemsTuple_); AllocatorType::Free(itemsTuple_);
#if RAPIDJSON_SCHEMA_USE_STDREGEX #if RAPIDJSON_SCHEMA_HAS_REGEX
if (pattern_) { if (pattern_) {
pattern_->~RegexType(); pattern_->~RegexType();
allocator_->Free(pattern_); allocator_->Free(pattern_);
...@@ -905,7 +913,9 @@ private: ...@@ -905,7 +913,9 @@ private:
kTotalSchemaType kTotalSchemaType
}; };
#if RAPIDJSON_SCHEMA_USE_STDREGEX #if RAPIDJSON_SCHEMA_USE_INTERNALREGEX
typedef internal::GenericRegex<EncodingType> RegexType;
#elif RAPIDJSON_SCHEMA_USE_STDREGEX
typedef std::basic_regex<Ch> RegexType; typedef std::basic_regex<Ch> RegexType;
#else #else
typedef char RegexType; typedef char RegexType;
...@@ -969,7 +979,24 @@ private: ...@@ -969,7 +979,24 @@ private:
} }
} }
#if RAPIDJSON_SCHEMA_USE_STDREGEX #if RAPIDJSON_SCHEMA_USE_INTERNALREGEX
template <typename ValueType>
RegexType* CreatePattern(const ValueType& value) {
if (value.IsString()) {
RegexType* r = new (allocator_->Malloc(sizeof(RegexType))) RegexType(value.GetString());
if (!r->IsValid()) {
r->~RegexType();
r = 0;
}
return r;
}
return 0;
}
static bool IsPatternMatch(const RegexType* pattern, const Ch *str, SizeType) {
return pattern->Search(str);
}
#elif RAPIDJSON_SCHEMA_USE_STDREGEX
template <typename ValueType> template <typename ValueType>
RegexType* CreatePattern(const ValueType& value) { RegexType* CreatePattern(const ValueType& value) {
if (value.IsString()) if (value.IsString())
......
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