userver: userver/chaotic/validators_pattern.hpp Source File
Loading...
Searching...
No Matches
validators_pattern.hpp
1#pragma once
2
3#include <stdexcept>
4#include <string>
5
6#include <userver/utils/regex.hpp>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace chaotic {
11
12template <const std::string_view& Regex>
13struct Pattern final {
14 static const utils::regex kRegex;
15
16 static void Validate(const std::string& value) {
17 if (!utils::regex_search(value, kRegex)) throw std::runtime_error("doesn't match regex");
18 }
19};
20
21template <const std::string_view& Regex>
22inline const utils::regex Pattern<Regex>::kRegex{std::string{Regex}};
23
24} // namespace chaotic
25
26USERVER_NAMESPACE_END