summaryrefslogtreecommitdiff
path: root/src/desktop/Rule.cpp
blob: aa87a483036e2b4f5644a590b9cb2a0bbedb5938 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <re2/re2.h>
#include "../helpers/memory/Memory.hpp"
#include "Rule.hpp"
#include "../debug/Log.hpp"

CRuleRegexContainer::CRuleRegexContainer(const std::string& regex_) {
    const bool NEGATIVE = regex_.starts_with("negative:");

    negative = NEGATIVE;
    regex    = makeUnique<RE2>(NEGATIVE ? regex_.substr(9) : regex_);

    // TODO: maybe pop an error?
    if (!regex->ok())
        Debug::log(ERR, "RuleRegexContainer: regex {} failed to parse!", regex_);
}

bool CRuleRegexContainer::passes(const std::string& str) const {
    if (!regex)
        return false;

    return RE2::FullMatch(str, *regex) != negative;
}