7 std::vector<std::string> matchSingleRegex(
const std::regex& regex,
const std::vector<std::string>& toMatch) {
8 std::vector<std::string> matches;
9 for (
const auto& str : toMatch) {
10 if (std::regex_match(str, regex)) {
11 matches.push_back(str);
17 template <
typename RegistryT>
18 std::vector<std::string> matchValidators(
const Regexes& regexes,
const RegistryT& registry) {
19 auto getKeys = [](
auto& map) {
return utils::transform(map, [](
auto elem) {
return elem.first; }); };
20 auto toMatch = getKeys(registry);
21 if (regexes.empty()) {
24 auto matches =
utils::concatenate(regexes, [&toMatch](
auto& regex) {
return matchSingleRegex(regex, toMatch); });
25 std::sort(matches.begin(), matches.end());
26 auto eraseIt = std::unique(matches.begin(), matches.end());
27 matches.erase(eraseIt, matches.end());
31 template <
typename Val
idatorT>
32 ValidatorsWithName<ValidatorT> createValidators(
33 const Regexes& regexes,
const std::map<std::string, ValidatorFactory::CreationFcn<ValidatorT>>& registry) {
34 auto matches = matchValidators(regexes, registry);
36 return std::make_pair(match, std::unique_ptr<ValidatorT>(registry.at(match)()));
43 return validatorFactory;