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))
18 throw std::runtime_error("doesn't match regex");
19 }
20};
21
22template <const std::string_view& Regex>
23inline const utils::regex Pattern<Regex>::kRegex{std::string{Regex}};
24
25} // namespace chaotic
26
27USERVER_NAMESPACE_END