diff --git a/include/rapidjson/internal/regex.h b/include/rapidjson/internal/regex.h index fcf2600..f3333b2 100644 --- a/include/rapidjson/internal/regex.h +++ b/include/rapidjson/internal/regex.h @@ -65,8 +65,8 @@ public: typedef typename Encoding::Ch Ch; GenericRegex(const Ch* source, Allocator* allocator = 0) : states_(allocator, 256), ranges_(allocator, 256), root_(kRegexInvalidState), stateCount_(), rangeCount_(), anchorBegin_(), anchorEnd_() { - StringStream ss(source); - DecodedStream ds(ss); + GenericStringStream ss(source); + DecodedStream > ds(ss); Parse(ds); } @@ -83,7 +83,7 @@ public: } bool Match(const Ch* s) const { - StringStream is(s); + GenericStringStream is(s); return Match(is); } @@ -93,7 +93,7 @@ public: } bool Search(const Ch* s) const { - StringStream is(s); + GenericStringStream is(s); return Search(is); } diff --git a/include/rapidjson/schema.h b/include/rapidjson/schema.h index 55d91bf..fda3bf6 100644 --- a/include/rapidjson/schema.h +++ b/include/rapidjson/schema.h @@ -19,17 +19,25 @@ #include "pointer.h" #include // 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 #else #define RAPIDJSON_SCHEMA_USE_STDREGEX 0 #endif -#if RAPIDJSON_SCHEMA_USE_STDREGEX +#if RAPIDJSON_SCHEMA_USE_INTERNALREGEX +#include "internal/regex.h" +#elif RAPIDJSON_SCHEMA_USE_STDREGEX #include #endif -#if RAPIDJSON_SCHEMA_USE_STDREGEX +#if RAPIDJSON_SCHEMA_USE_INTERNALREGEX || RAPIDJSON_SCHEMA_USE_STDREGEX #define RAPIDJSON_SCHEMA_HAS_REGEX 1 #else #define RAPIDJSON_SCHEMA_HAS_REGEX 0 @@ -560,7 +568,7 @@ public: AllocatorType::Free(patternProperties_); } AllocatorType::Free(itemsTuple_); -#if RAPIDJSON_SCHEMA_USE_STDREGEX +#if RAPIDJSON_SCHEMA_HAS_REGEX if (pattern_) { pattern_->~RegexType(); allocator_->Free(pattern_); @@ -905,7 +913,9 @@ private: kTotalSchemaType }; -#if RAPIDJSON_SCHEMA_USE_STDREGEX +#if RAPIDJSON_SCHEMA_USE_INTERNALREGEX + typedef internal::GenericRegex RegexType; +#elif RAPIDJSON_SCHEMA_USE_STDREGEX typedef std::basic_regex RegexType; #else typedef char RegexType; @@ -969,7 +979,24 @@ private: } } -#if RAPIDJSON_SCHEMA_USE_STDREGEX +#if RAPIDJSON_SCHEMA_USE_INTERNALREGEX + template + 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 RegexType* CreatePattern(const ValueType& value) { if (value.IsString())