parent
57921d7dbd
commit
31422ae25d
5 changed files with 61 additions and 34 deletions
|
|
@ -2,12 +2,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
//NOLINTNEXTLINE
|
||||
namespace re2 {
|
||||
class RE2;
|
||||
};
|
||||
#include "Rule.hpp"
|
||||
|
||||
class CLayerRule {
|
||||
public:
|
||||
|
|
@ -27,10 +22,10 @@ class CLayerRule {
|
|||
RULE_ZUMBA,
|
||||
};
|
||||
|
||||
eRuleType ruleType = RULE_INVALID;
|
||||
eRuleType ruleType = RULE_INVALID;
|
||||
|
||||
const std::string targetNamespace;
|
||||
const std::string rule;
|
||||
const std::string targetNamespace;
|
||||
const std::string rule;
|
||||
|
||||
std::unique_ptr<re2::RE2> rTargetNamespaceRegex;
|
||||
CRuleRegexContainer targetNamespaceRegex;
|
||||
};
|
||||
16
src/desktop/Rule.cpp
Normal file
16
src/desktop/Rule.cpp
Normal file
|
|
@ -0,0 +1,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;
|
||||
}
|
||||
21
src/desktop/Rule.hpp
Normal file
21
src/desktop/Rule.hpp
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
//NOLINTNEXTLINE
|
||||
namespace re2 {
|
||||
class RE2;
|
||||
};
|
||||
|
||||
class CRuleRegexContainer {
|
||||
public:
|
||||
CRuleRegexContainer() = default;
|
||||
|
||||
CRuleRegexContainer(const std::string& regex);
|
||||
|
||||
bool passes(const std::string& str) const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<re2::RE2> regex;
|
||||
bool negative = false;
|
||||
};
|
||||
|
|
@ -2,12 +2,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
//NOLINTNEXTLINE
|
||||
namespace re2 {
|
||||
class RE2;
|
||||
};
|
||||
#include "Rule.hpp"
|
||||
|
||||
class CWindowRule {
|
||||
public:
|
||||
|
|
@ -65,9 +60,9 @@ class CWindowRule {
|
|||
std::string szWorkspace = ""; // empty means any
|
||||
|
||||
// precompiled regexes
|
||||
std::unique_ptr<re2::RE2> rTitle;
|
||||
std::unique_ptr<re2::RE2> rClass;
|
||||
std::unique_ptr<re2::RE2> rInitialTitle;
|
||||
std::unique_ptr<re2::RE2> rInitialClass;
|
||||
std::unique_ptr<re2::RE2> rV1Regex;
|
||||
CRuleRegexContainer rTitle;
|
||||
CRuleRegexContainer rClass;
|
||||
CRuleRegexContainer rInitialTitle;
|
||||
CRuleRegexContainer rInitialClass;
|
||||
CRuleRegexContainer rV1Regex;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue