+ bool matches = false;
+
+ for (int i = 0; i < _highlightRuleList.count(); i++) {
+ const HighlightRule &rule = _highlightRuleList.at(i);
+ if (!rule.isEnabled)
+ continue;
+
+ if (rule.chanName.size() > 0 && rule.chanName.compare(".*") != 0) {
+ if (rule.chanName.startsWith("!")) {
+ QRegExp rx(rule.chanName.mid(1), Qt::CaseInsensitive);
+ if (rx.exactMatch(bufferName))
+ continue;
+ }
+ else {
+ QRegExp rx(rule.chanName, Qt::CaseInsensitive);
+ if (!rx.exactMatch(bufferName))
+ continue;
+ }
+ }
+
+ QRegExp rx;
+ if (rule.isRegEx) {
+ rx = QRegExp(rule.name, rule.isCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
+ } else {
+ rx = QRegExp("(^|\\W)" + QRegExp::escape(rule.name) + "(\\W|$)", rule.isCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
+ }
+ bool nameMatch = (rx.indexIn(stripFormatCodes(msgContents)) >= 0);
+
+ bool senderMatch;
+ if (rule.sender.isEmpty()) {
+ senderMatch = true;
+ } else {
+ if (rule.isRegEx) {
+ rx = QRegExp(rule.sender, rule.isCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
+ } else {
+ rx = QRegExp(rule.sender, Qt::CaseInsensitive, QRegExp::Wildcard);
+ }
+ senderMatch = rx.exactMatch(msgSender);
+ }
+
+ if (nameMatch && senderMatch) {
+ // If an inverse rule matches, then we know that we never want to return a highlight.
+ if (rule.isInverse) {
+ return false;
+ } else {
+ matches = true;
+ }
+ }
+ }
+
+ if (matches)
+ return true;
+