Readd RAPIDJSON_SCHEMA_HAS_REGEX and fix compilation

This commit is contained in:
Milo Yip 2015-05-08 13:48:37 +08:00
parent 6b3244ead3
commit 490630b7cc
2 changed files with 9 additions and 3 deletions

View File

@ -18,8 +18,6 @@
#include "document.h" #include "document.h"
#include <cmath> // HUGE_VAL, abs, floor #include <cmath> // HUGE_VAL, abs, floor
#define RAPIDJSON_SCHEMA_USE_STDREGEX 0
#if !defined(RAPIDJSON_SCHEMA_USE_STDREGEX) && (__cplusplus >=201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)) #if !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
@ -30,6 +28,12 @@
#include <regex> #include <regex>
#endif #endif
#if RAPIDJSON_SCHEMA_USE_STDREGEX
#define RAPIDJSON_SCHEMA_HAS_REGEX 1
#else
#define RAPIDJSON_SCHEMA_HAS_REGEX 0
#endif
#if defined(__GNUC__) #if defined(__GNUC__)
RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(effc++) RAPIDJSON_DIAG_OFF(effc++)
@ -669,7 +673,7 @@ private:
static bool IsPatternMatch(const std::basic_regex<Ch>* pattern, const Ch *str, SizeType length) { static bool IsPatternMatch(const std::basic_regex<Ch>* 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>

View File

@ -385,6 +385,7 @@ TEST(SchemaValidator, Object_SchemaDependencies) {
VALIDATE(s, "{\"name\": \"John Doe\", \"billing_address\" : \"555 Debtor's Lane\"}", true); VALIDATE(s, "{\"name\": \"John Doe\", \"billing_address\" : \"555 Debtor's Lane\"}", true);
} }
#if RAPIDJSON_SCHEMA_HAS_REGEX
TEST(SchemaValidator, Object_PatternProperties) { TEST(SchemaValidator, Object_PatternProperties) {
Document sd; Document sd;
sd.Parse( sd.Parse(
@ -424,6 +425,7 @@ TEST(SchemaValidator, Object_PatternProperties_AdditionalProperties) {
VALIDATE(s, "{ \"keyword\": \"value\" }", true); VALIDATE(s, "{ \"keyword\": \"value\" }", true);
VALIDATE(s, "{ \"keyword\": 42 }", false); VALIDATE(s, "{ \"keyword\": 42 }", false);
} }
#endif
TEST(SchemaValidator, Array) { TEST(SchemaValidator, Array) {
Document sd; Document sd;