2024-12-21 23:07:23 +00:00
|
|
|
#include <re2/re2.h>
|
2025-01-23 21:55:41 +01:00
|
|
|
#include "../helpers/memory/Memory.hpp"
|
|
|
|
|
#include "Rule.hpp"
|
2025-01-17 18:24:10 +01:00
|
|
|
#include "../debug/Log.hpp"
|
2024-12-21 23:07:23 +00:00
|
|
|
|
|
|
|
|
CRuleRegexContainer::CRuleRegexContainer(const std::string& regex_) {
|
|
|
|
|
const bool NEGATIVE = regex_.starts_with("negative:");
|
|
|
|
|
|
|
|
|
|
negative = NEGATIVE;
|
2025-01-23 21:55:41 +01:00
|
|
|
regex = makeUnique<RE2>(NEGATIVE ? regex_.substr(9) : regex_);
|
2025-01-17 18:24:10 +01:00
|
|
|
|
|
|
|
|
// TODO: maybe pop an error?
|
|
|
|
|
if (!regex->ok())
|
|
|
|
|
Debug::log(ERR, "RuleRegexContainer: regex {} failed to parse!", regex_);
|
2024-12-21 23:07:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CRuleRegexContainer::passes(const std::string& str) const {
|
|
|
|
|
if (!regex)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return RE2::FullMatch(str, *regex) != negative;
|
|
|
|
|
}
|