Browse Source

refactor(messages): Replace QRegExp with QRegularExpression

reviewable/pr5703/r42
Mick Sayson 6 years ago
parent
commit
c779d52aef
  1. 17
      src/model/message.cpp
  2. 9
      src/model/message.h

17
src/model/message.cpp

@ -24,9 +24,11 @@ @@ -24,9 +24,11 @@
void MessageProcessor::SharedParams::onUserNameSet(const QString& username)
{
QString sanename = username;
sanename.remove(QRegExp("[\\t\\n\\v\\f\\r\\x0000]"));
nameMention = QRegExp("\\b" + QRegExp::escape(username) + "\\b", Qt::CaseInsensitive);
sanitizedNameMention = QRegExp("\\b" + QRegExp::escape(sanename) + "\\b", Qt::CaseInsensitive);
sanename.remove(QRegularExpression("[\\t\\n\\v\\f\\r\\x0000]"));
nameMention = QRegularExpression("\\b" + QRegularExpression::escape(username) + "\\b",
QRegularExpression::CaseInsensitiveOption);
sanitizedNameMention = QRegularExpression("\\b" + QRegularExpression::escape(sanename) + "\\b",
QRegularExpression::CaseInsensitiveOption);
}
MessageProcessor::MessageProcessor(const MessageProcessor::SharedParams& sharedParams)
@ -73,12 +75,15 @@ Message MessageProcessor::processIncomingMessage(bool isAction, QString const& m @@ -73,12 +75,15 @@ Message MessageProcessor::processIncomingMessage(bool isAction, QString const& m
auto sanitizedNameMention = sharedParams.GetSanitizedNameMention();
for (auto const& mention : {nameMention, sanitizedNameMention}) {
if (mention.indexIn(ret.content) == -1) {
auto matchIt = mention.globalMatch(ret.content);
if (!matchIt.hasNext()) {
continue;
}
auto pos = static_cast<size_t>(mention.pos(0));
auto length = static_cast<size_t>(mention.matchedLength());
auto match = matchIt.next();
auto pos = static_cast<size_t>(match.capturedStart());
auto length = static_cast<size_t>(match.capturedLength());
ret.metadata.push_back({MessageMetadataType::selfMention, pos, pos + length});
break;

9
src/model/message.h

@ -21,6 +21,7 @@ @@ -21,6 +21,7 @@
#define MESSAGE_H
#include <QDateTime>
#include <QRegularExpression>
#include <QString>
#include <vector>
@ -66,19 +67,19 @@ public: @@ -66,19 +67,19 @@ public:
{
public:
QRegExp GetNameMention() const
QRegularExpression GetNameMention() const
{
return nameMention;
}
QRegExp GetSanitizedNameMention() const
QRegularExpression GetSanitizedNameMention() const
{
return sanitizedNameMention;
}
void onUserNameSet(const QString& username);
private:
QRegExp nameMention;
QRegExp sanitizedNameMention;
QRegularExpression nameMention;
QRegularExpression sanitizedNameMention;
};
MessageProcessor(const SharedParams& sharedParams);

Loading…
Cancel
Save