From 31422ae25dee33dd000798b64a80bd7fd08d2ece Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 21 Dec 2024 23:07:23 +0000 Subject: windowrules: add negative: prefix for negating a regex fixes #8799 --- src/desktop/Rule.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/desktop/Rule.cpp (limited to 'src/desktop/Rule.cpp') diff --git a/src/desktop/Rule.cpp b/src/desktop/Rule.cpp new file mode 100644 index 00000000..dd1848d4 --- /dev/null +++ b/src/desktop/Rule.cpp @@ -0,0 +1,16 @@ +#include "Rule.hpp" +#include + +CRuleRegexContainer::CRuleRegexContainer(const std::string& regex_) { + const bool NEGATIVE = regex_.starts_with("negative:"); + + negative = NEGATIVE; + regex = std::make_unique(NEGATIVE ? regex_.substr(9) : regex_); +} + +bool CRuleRegexContainer::passes(const std::string& str) const { + if (!regex) + return false; + + return RE2::FullMatch(str, *regex) != negative; +} \ No newline at end of file -- cgit v1.2.3