aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/desktop/Rule.cpp
blob: dd1848d485e4c7e8e87d8586944a8954ddb4a590 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "Rule.hpp"
#include <re2/re2.h>

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

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

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

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