From 7ca04fbf45d520bc6b3544fb8ff8cf60c5d9762f Mon Sep 17 00:00:00 2001 From: Albert S Date: Sat, 17 Apr 2021 12:10:59 +0200 Subject: [PATCH] utils: Add regex_callback_extractor() --- utils.cpp | 11 +++++++++++ utils.h | 1 + 2 files changed, 12 insertions(+) diff --git a/utils.cpp b/utils.cpp index 3df6306..1510217 100644 --- a/utils.cpp +++ b/utils.cpp @@ -175,3 +175,14 @@ std::string utils::toISODate(time_t t) } return std::string{result}; } + +void utils::regex_callback_extractor(std::regex regex, const std::string &input, std::function callback) +{ + auto begin = std::sregex_iterator(input.begin(), input.end(), regex); + auto end = std::sregex_iterator(); + for(auto it = begin; it != end; it++) + { + std::smatch smatch = *it; + callback(smatch); + } +} diff --git a/utils.h b/utils.h index d19be1b..de5a900 100644 --- a/utils.h +++ b/utils.h @@ -60,6 +60,7 @@ template std::vector getAll(std::multimap map, T key std::string regex_callback_replacer(std::regex regex, const std::string &input, std::function callback); +void regex_callback_extractor(std::regex regex, const std::string &input, std::function callback); std::string readCompleteFile(std::string_view filepath); inline std::string nz(const char *s)