-
-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new search predicate to enable searching for messages matching a …
…regex (#3282) Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
- Loading branch information
1 parent
c1a3814
commit 06245f3
Showing
6 changed files
with
107 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "RegexPredicate.hpp" | ||
|
||
namespace chatterino { | ||
|
||
RegexPredicate::RegexPredicate(const QString ®ex) | ||
: regex_(regex, QRegularExpression::CaseInsensitiveOption) | ||
{ | ||
} | ||
|
||
bool RegexPredicate::appliesTo(const Message &message) | ||
{ | ||
if (!regex_.isValid()) | ||
{ | ||
return false; | ||
} | ||
|
||
QRegularExpressionMatch match = regex_.match(message.messageText); | ||
|
||
return match.hasMatch(); | ||
} | ||
|
||
} // namespace chatterino |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include "QRegularExpression" | ||
#include "messages/search/MessagePredicate.hpp" | ||
|
||
namespace chatterino { | ||
|
||
/** | ||
* @brief MessagePredicate checking whether the message matches a given regex. | ||
* | ||
* This predicate will only allow messages whose `messageText` match the given | ||
* regex. | ||
*/ | ||
class RegexPredicate : public MessagePredicate | ||
{ | ||
public: | ||
/** | ||
* @brief Create a RegexPredicate with a regex to match the message against. | ||
* | ||
* The message is being matched case-insensitively. | ||
* | ||
* @param regex the regex to match the message against | ||
*/ | ||
RegexPredicate(const QString ®ex); | ||
|
||
/** | ||
* @brief Checks whether the message matches the regex passed in the | ||
* constructor | ||
* | ||
* The check is done case-insensitively. | ||
* | ||
* @param message the message to check | ||
* @return true if the message matches the regex, false otherwise | ||
*/ | ||
bool appliesTo(const Message &message); | ||
|
||
private: | ||
/// Holds the regular expression to match the message against | ||
QRegularExpression regex_; | ||
}; | ||
|
||
} // namespace chatterino |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters