Created
February 17, 2023 05:26
-
-
Save mrowrpurr/4ffe08a3201d954b11d30b85e27187ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MatchesRegexMatcher { | |
std::vector<std::string> _patterns; | |
public: | |
template <typename... Args> | |
MatchesRegexMatcher(std::string pattern, Args... args) : _patterns({pattern, args...}) {} | |
const std::vector<std::string>& GetPatterns() const { return _patterns; } | |
bool Matches(const std::string& text) const { | |
for (const auto& pattern : _patterns) { | |
if (!std::regex_search(text, std::regex(pattern, std::regex_constants::icase))) { | |
return false; | |
} | |
} | |
return true; | |
} | |
friend std::ostream& operator<<(std::ostream& os, const MatchesRegexMatcher& matcher) { | |
if (matcher._patterns.size() == 1) { | |
return os << "match regular expression /" << matcher._patterns[0] << "/"; | |
} else { | |
os << "match regular expressions:"; | |
for (const auto& pattern : matcher._patterns) { | |
os << " /" << pattern << "/"; | |
} | |
return os; | |
} | |
} | |
}; | |
#define MatchesRegex(...) Fulfills(MatchesRegexMatcher(__VA_ARGS__)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment