From 46bafd05b85dd690b47e9c562effa4c01c72899c Mon Sep 17 00:00:00 2001 From: Patrick Boettcher Date: Sat, 18 Feb 2017 13:05:45 +0100 Subject: [PATCH] regex: on gcc < 4.9 do not use std::regex This makes that patternProperties always succeed now if gcc < 4.9 --- src/json-validator.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/json-validator.cpp b/src/json-validator.cpp index e903e89..503f6ae 100644 --- a/src/json-validator.cpp +++ b/src/json-validator.cpp @@ -25,12 +25,23 @@ */ #include -#include #include using nlohmann::json; using nlohmann::json_uri; +#if defined(__GNUC__) + #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) + #if GCC_VERSION < 40900 + #define NO_STD_REGEX + #endif + #undef GCC_VERSION +#endif + +#ifndef NO_STD_REGEX + #include +#endif + namespace { @@ -597,13 +608,20 @@ void json_validator::validate_object(const json &instance, const json &schema, c for (auto pp = patternProperties.begin(); pp != patternProperties.end(); ++pp) { +#ifndef NO_STD_REGEX std::regex re(pp.key(), std::regex::ECMAScript); if (std::regex_search(child.key(), re)) { validate(child.value(), pp.value(), child_name); property_or_patternProperties_has_validated = true; } +#else + // accept everything in case of a patternProperty + property_or_patternProperties_has_validated = true; + break; +#endif } + if (property_or_patternProperties_has_validated) continue; @@ -697,6 +715,7 @@ void json_validator::validate_string(const json &instance, const json &schema, c throw std::out_of_range(s.str()); } +#ifndef NO_STD_REGEX // pattern attr = schema.find("pattern"); if (attr != schema.end()) { @@ -704,6 +723,7 @@ void json_validator::validate_string(const json &instance, const json &schema, c if (!std::regex_search(instance.get(), re)) throw std::invalid_argument(instance.get() + " does not match regex pattern: " + attr.value().get() + " for " + name); } +#endif // format attr = schema.find("format");