| 1234567891011121314151617181920212223 |
- #pragma once
- #include <regex>
- #include <string>
- #include <unordered_map>
- namespace jvalidate::detail {
- class RegexEngine {
- public:
- virtual ~RegexEngine() = default;
- virtual bool operator()(std::string const & regex, std::string const & text) = 0;
- };
- class StdRegexEngine final : public RegexEngine {
- private:
- std::unordered_map<std::string, std::regex> cache_;
- public:
- bool operator()(std::string const & regex, std::string const & text) {
- return std::regex_match(text, cache_.try_emplace(regex, regex).first->second);
- }
- };
- }
|