diff options
Diffstat (limited to 'Swift/Controllers/HighlightRule.cpp')
| -rw-r--r-- | Swift/Controllers/HighlightRule.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/Swift/Controllers/HighlightRule.cpp b/Swift/Controllers/HighlightRule.cpp index 40b7560..021e15d 100644 --- a/Swift/Controllers/HighlightRule.cpp +++ b/Swift/Controllers/HighlightRule.cpp | |||
| @@ -10,13 +10,15 @@ | |||
| 10 | * See the COPYING file for more information. | 10 | * See the COPYING file for more information. |
| 11 | */ | 11 | */ |
| 12 | 12 | ||
| 13 | #include <Swift/Controllers/HighlightRule.h> | ||
| 14 | |||
| 13 | #include <algorithm> | 15 | #include <algorithm> |
| 16 | |||
| 14 | #include <boost/algorithm/string.hpp> | 17 | #include <boost/algorithm/string.hpp> |
| 15 | #include <boost/lambda/lambda.hpp> | 18 | #include <boost/lambda/lambda.hpp> |
| 16 | 19 | ||
| 17 | #include <Swiften/Base/foreach.h> | ||
| 18 | #include <Swiften/Base/Regex.h> | 20 | #include <Swiften/Base/Regex.h> |
| 19 | #include <Swift/Controllers/HighlightRule.h> | 21 | #include <Swiften/Base/foreach.h> |
| 20 | 22 | ||
| 21 | namespace Swift { | 23 | namespace Swift { |
| 22 | 24 | ||
| @@ -69,10 +71,21 @@ bool HighlightRule::isMatch(const std::string& body, const std::string& sender, | |||
| 69 | bool matchesKeyword = keywords_.empty() && (nick.empty() || !nickIsKeyword_); | 71 | bool matchesKeyword = keywords_.empty() && (nick.empty() || !nickIsKeyword_); |
| 70 | bool matchesSender = senders_.empty(); | 72 | bool matchesSender = senders_.empty(); |
| 71 | 73 | ||
| 72 | if (!matchesKeyword && nickIsKeyword_ && !nick.empty()) { | 74 | if (!matchesKeyword) { |
| 73 | if (boost::regex_search(body, regexFromString(nick))) { | 75 | // check if the nickname matches |
| 76 | if (nickIsKeyword_ && !nick.empty() && boost::regex_search(body, regexFromString(nick))) { | ||
| 74 | matchesKeyword = true; | 77 | matchesKeyword = true; |
| 75 | } | 78 | } |
| 79 | |||
| 80 | // check if a keyword matches | ||
| 81 | if (!matchesKeyword && !keywords_.empty()) { | ||
| 82 | foreach (const boost::regex &keyword, keywordRegex_) { | ||
| 83 | if (boost::regex_search(body, keyword)) { | ||
| 84 | matchesKeyword = true; | ||
| 85 | break; | ||
| 86 | } | ||
| 87 | } | ||
| 88 | } | ||
| 76 | } | 89 | } |
| 77 | 90 | ||
| 78 | foreach (const boost::regex & rx, senderRegex_) { | 91 | foreach (const boost::regex & rx, senderRegex_) { |
Swift