Compare commits
No commits in common. "0e709f25cd49484134bea2cfc56aa783f342c52d" and "30e9a4df7d7edc161d36767f6fa21ba83864829e" have entirely different histories.
0e709f25cd
...
30e9a4df7d
21
LICENSE
21
LICENSE
|
@ -1,21 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2022-2023 blank X
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
59
filters.cpp
59
filters.cpp
|
@ -94,64 +94,55 @@ const std::string* StringFilter::error() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StringFilter::_match_no_regex(const LogcatEntry& entry) const {
|
bool StringFilter::_match_no_regex(const LogcatEntry& entry) const {
|
||||||
|
bool matched;
|
||||||
if (this->exact_match) {
|
if (this->exact_match) {
|
||||||
switch (this->key) {
|
switch (this->key) {
|
||||||
case FilterKey::User: return entry.user && *entry.user == this->other;
|
case FilterKey::User: matched = entry.user.value_or("") == this->other; break;
|
||||||
case FilterKey::Tag: return entry.tag == this->other;
|
case FilterKey::Tag: matched = entry.tag == this->other; break;
|
||||||
case FilterKey::Message: return entry.message == this->other;
|
case FilterKey::Message: matched = entry.message == this->other; break;
|
||||||
default: throw std::runtime_error("StringFilter::match received unhandled key");
|
default: throw std::runtime_error("StringFilter::match received unhandled key");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (this->key) {
|
switch (this->key) {
|
||||||
case FilterKey::User: return entry.user && entry.user->find(this->other) != std::string::npos;
|
case FilterKey::User: matched = entry.user.value_or("").find(this->other) != std::string::npos; break;
|
||||||
case FilterKey::Tag: return entry.tag.find(this->other) != std::string::npos;
|
case FilterKey::Tag: matched = entry.tag.find(this->other) != std::string::npos; break;
|
||||||
case FilterKey::Message: return entry.message.find(this->other) != std::string::npos;
|
case FilterKey::Message: matched = entry.message.find(this->other) != std::string::npos; break;
|
||||||
default: throw std::runtime_error("StringFilter::match received unhandled key");
|
default: throw std::runtime_error("StringFilter::match received unhandled key");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return !this->inverted ? matched : !matched;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StringFilter::_match_regex(const LogcatEntry& entry) const {
|
bool StringFilter::match(const LogcatEntry& entry) const {
|
||||||
|
bool matched;
|
||||||
|
|
||||||
|
if (this->error()) {
|
||||||
|
log(std::string("StringFilter::match called despite there being an error: ") + *this->error());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!this->other.starts_with("regex:")) {
|
||||||
|
return this->_match_no_regex(entry);
|
||||||
|
}
|
||||||
if (!this->_regex) {
|
if (!this->_regex) {
|
||||||
log("StringFilter::match called with a regex despite there being no regex");
|
log("StringFilter::match called with a regex despite there being no regex");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool matched;
|
std::string str;
|
||||||
const std::string* str;
|
|
||||||
regmatch_t pmatch[1];
|
regmatch_t pmatch[1];
|
||||||
int eflags = REG_STARTEND;
|
|
||||||
|
|
||||||
switch (this->key) {
|
switch (this->key) {
|
||||||
case FilterKey::User: str = entry.user ? &*entry.user : nullptr; break;
|
case FilterKey::User: str = entry.user.value_or(""); break;
|
||||||
case FilterKey::Tag: str = &entry.tag; break;
|
case FilterKey::Tag: str = entry.tag; break;
|
||||||
case FilterKey::Message: str = &entry.message; break;
|
case FilterKey::Message: str = entry.message; break;
|
||||||
default: throw std::runtime_error("StringFilter::match received unhandled key");
|
default: throw std::runtime_error("StringFilter::match received unhandled key");
|
||||||
}
|
}
|
||||||
pmatch[0].rm_so = 0;
|
pmatch[0].rm_so = 0;
|
||||||
pmatch[0].rm_eo = str ? static_cast<regoff_t>(str->size()) : 0;
|
pmatch[0].rm_eo = static_cast<regoff_t>(str.size());
|
||||||
if (!this->exact_match) {
|
|
||||||
eflags |= REG_NOSUB;
|
|
||||||
}
|
|
||||||
|
|
||||||
matched = this->_regex->match(str ? str->data() : "", 1, pmatch, eflags);
|
matched = this->_regex->match(str.data(), 1, pmatch, REG_STARTEND);
|
||||||
if (this->exact_match) {
|
if (this->exact_match) {
|
||||||
matched = matched && pmatch[0].rm_so == 0 && str
|
matched = matched && pmatch[0].rm_so == 0 && static_cast<size_t>(pmatch[0].rm_eo) == str.size();
|
||||||
? static_cast<size_t>(pmatch[0].rm_eo) == str->size()
|
|
||||||
: pmatch[0].rm_so == 0;
|
|
||||||
}
|
}
|
||||||
return matched;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool StringFilter::match(const LogcatEntry& entry) const {
|
|
||||||
if (this->error()) {
|
|
||||||
log(std::string("StringFilter::match called despite there being an error: ") + *this->error());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool matched = !this->other.starts_with("regex:")
|
|
||||||
? this->_match_no_regex(entry)
|
|
||||||
: this->_match_regex(entry);
|
|
||||||
return !this->inverted ? matched : !matched;
|
return !this->inverted ? matched : !matched;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,6 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _match_no_regex(const LogcatEntry& entry) const;
|
bool _match_no_regex(const LogcatEntry& entry) const;
|
||||||
bool _match_regex(const LogcatEntry& entry) const;
|
|
||||||
|
|
||||||
std::string _error;
|
std::string _error;
|
||||||
std::optional<Pcre2Regex> _regex;
|
std::optional<Pcre2Regex> _regex;
|
||||||
|
|
Loading…
Reference in New Issue