ignorephrase format

This commit is contained in:
hemirt
2018-09-30 13:39:05 +02:00
committed by pajlada
parent 6ca4f661a7
commit e7f74aa8ca
+23 -14
View File
@@ -20,14 +20,14 @@ class IgnorePhrase
public:
bool operator==(const IgnorePhrase &other) const
{
return std::tie(this->pattern_, this->isRegex_, this->isBlock_, this->replace_,
this->isCaseSensitive_) == std::tie(other.pattern_, other.isRegex_,
other.isBlock_, other.replace_,
other.isCaseSensitive_);
return std::tie(this->pattern_, this->isRegex_, this->isBlock_,
this->replace_, this->isCaseSensitive_) ==
std::tie(other.pattern_, other.isRegex_, other.isBlock_,
other.replace_, other.isCaseSensitive_);
}
IgnorePhrase(const QString &pattern, bool isRegex, bool isBlock, const QString &replace,
bool isCaseSensitive)
IgnorePhrase(const QString &pattern, bool isRegex, bool isBlock,
const QString &replace, bool isCaseSensitive)
: pattern_(pattern)
, isRegex_(isRegex)
, regex_(pattern)
@@ -36,9 +36,11 @@ public:
, isCaseSensitive_(isCaseSensitive)
{
if (this->isCaseSensitive_) {
regex_.setPatternOptions(QRegularExpression::UseUnicodePropertiesOption);
regex_.setPatternOptions(
QRegularExpression::UseUnicodePropertiesOption);
} else {
regex_.setPatternOptions(QRegularExpression::CaseInsensitiveOption |
regex_.setPatternOptions(
QRegularExpression::CaseInsensitiveOption |
QRegularExpression::UseUnicodePropertiesOption);
}
}
@@ -61,8 +63,10 @@ public:
bool isMatch(const QString &subject) const
{
return !this->pattern_.isEmpty() &&
(this->isRegex() ? (this->regex_.isValid() && this->regex_.match(subject).hasMatch())
: subject.contains(this->pattern_, this->caseSensitivity()));
(this->isRegex() ? (this->regex_.isValid() &&
this->regex_.match(subject).hasMatch())
: subject.contains(this->pattern_,
this->caseSensitivity()));
}
const QRegularExpression &getRegex() const
@@ -98,11 +102,13 @@ public:
bool containsEmote() const
{
if (!this->emotesChecked_) {
const auto &accvec = getApp()->accounts->twitch.accounts.getVector();
const auto &accvec =
getApp()->accounts->twitch.accounts.getVector();
for (const auto &acc : accvec) {
const auto &accemotes = *acc->accessEmotes();
for (const auto &emote : accemotes.emotes) {
if (this->replace_.contains(emote.first.string, Qt::CaseSensitive)) {
if (this->replace_.contains(emote.first.string,
Qt::CaseSensitive)) {
this->emotes_.emplace(emote.first, emote.second);
}
}
@@ -151,7 +157,9 @@ struct Deserialize<chatterino::IgnorePhrase> {
if (!value.IsObject()) {
return chatterino::IgnorePhrase(
QString(), false, false,
::chatterino::getSettings()->ignoredPhraseReplace.getValue(), true);
::chatterino::getSettings()
->ignoredPhraseReplace.getValue(),
true);
}
QString _pattern;
@@ -166,7 +174,8 @@ struct Deserialize<chatterino::IgnorePhrase> {
chatterino::rj::getSafe(value, "replaceWith", _replace);
chatterino::rj::getSafe(value, "caseSensitive", _caseSens);
return chatterino::IgnorePhrase(_pattern, _isRegex, _isBlock, _replace, _caseSens);
return chatterino::IgnorePhrase(_pattern, _isRegex, _isBlock,
_replace, _caseSens);
}
};
} // namespace Settings