#pragma once #include #include #include #include #include #include namespace jvalidate::detail { class StdRegexEngine { public: std::regex regex_; public: StdRegexEngine(std::string const & regex) : regex_(detail::regex_escape(regex)) {} bool search(std::string const & text) const { return std::regex_search(text, regex_); } }; } namespace jvalidate { template class ValidatorT { private: schema::Node const & schema_; ValidationConfig cfg_; std::unordered_map regex_cache_; public: ValidatorT(schema::Node const & schema, ValidationConfig const & cfg = {}) : schema_(schema), cfg_(cfg) {} template requires(not MutableAdapter) bool validate(A const & json, ValidationResult * result = nullptr) { EXPECT_M(not cfg_.construct_default_values, "Cannot perform mutations on an immutable JSON Adapter"); return static_cast( ValidationVisitor(json, schema_, cfg_, regex_cache_, result).validate()); } template bool validate(A const & json, ValidationResult * result = nullptr) { return static_cast( ValidationVisitor(json, schema_, cfg_, regex_cache_, result).validate()); } template requires(not Adapter) bool validate(JSON & json, ValidationResult * result = nullptr) { return validate(adapter::AdapterFor(json), result); } }; class Validator : public ValidatorT<> { public: using Validator::ValidatorT::ValidatorT; }; }