| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- #pragma once
- #include <regex>
- #include <unordered_map>
- #include <jvalidate/forward.h>
- #include <jvalidate/status.h>
- #include <jvalidate/validation_visitor.h>
- namespace jvalidate::detail {
- class StdRegexEngine {
- public:
- std::regex regex_;
- public:
- StdRegexEngine(std::string const & regex) : regex_(regex) {}
- bool search(std::string const & text) const { return std::regex_search(text, regex_); }
- };
- }
- namespace jvalidate {
- template <RegexEngine RE = detail::StdRegexEngine> class ValidatorT {
- private:
- schema::Node const & schema_;
- std::unordered_map<std::string, RE> regex_cache_;
- public:
- ValidatorT(schema::Node const & schema) : schema_(schema) {}
- template <Adapter A>
- Status validate(A const & json, ValidationResult const * result = nullptr) const {
- return ValidationVisitor<A, RE>(json, schema_, regex_cache_, result).validate();
- }
- };
- class Validator : public ValidatorT<> {
- public:
- using Validator::ValidatorT::ValidatorT;
- };
- }
|