aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vrátil <[email protected]>2017-10-13 17:05:04 +0200
committerDaniel Vrátil <[email protected]>2017-10-13 17:05:04 +0200
commitf9d8015570b0a670ff68a6f850c2dcbc7d123138 (patch)
tree74d779d9d8ab17743e37e4b48731128e28c5439e
parenta3fe4a09d1428caa64deab4b43cf134e7165116d (diff)
Port UUEncode parsing to QRegularExpression
Reviewers: vkrause Reviewed By: vkrause Subscribers: mlaurent, #kde_pim Tags: #kde_pim Differential Revision: https://phabricator.kde.org/D8247
-rw-r--r--src/kmime_parsers.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/kmime_parsers.cpp b/src/kmime_parsers.cpp
index 540cf8f..2b7102b 100644
--- a/src/kmime_parsers.cpp
+++ b/src/kmime_parsers.cpp
@@ -22,7 +22,7 @@
*/
#include "kmime_parsers.h"
-#include <QRegExp>
+#include <QRegularExpression>
#include <QByteArray>
using namespace KMime::Parser;
@@ -176,13 +176,16 @@ bool UUEncoded::parse()
int currentPos = 0;
bool success = true, firstIteration = true;
+ const auto srcStr = QString::fromLatin1(m_src);
+ const QRegularExpression beginRegex(QStringLiteral("begin [0-9][0-9][0-9]"));
+ const QRegularExpression subjectRegex(QStringLiteral("[0-9]+/[0-9]+"));
+
while (success) {
int beginPos = currentPos, uuStart = currentPos, endPos = 0, lineCount = 0, MCount = 0, pos = 0, len = 0;
bool containsBegin = false, containsEnd = false;
QByteArray tmp, fileName;
- if ((beginPos = QString::fromLatin1(m_src).indexOf(QRegExp(QStringLiteral("begin [0-9][0-9][0-9]")),
- currentPos)) > -1 &&
+ if ((beginPos = srcStr.indexOf(beginRegex, currentPos)) > -1 &&
(beginPos == 0 || m_src.at(beginPos - 1) == '\n')) {
containsBegin = true;
uuStart = m_src.indexOf('\n', beginPos);
@@ -226,9 +229,9 @@ bool UUEncoded::parse()
if ((!containsBegin || !containsEnd) && !m_subject.isNull()) {
// message may be split up => parse subject
- QRegExp rx(QStringLiteral("[0-9]+/[0-9]+"));
- pos = rx.indexIn(QLatin1String(m_subject), 0);
- len = rx.matchedLength();
+ const auto match = subjectRegex.match(QLatin1String(m_subject));
+ pos = match.capturedStart(0);
+ len = match.capturedLength(0);
if (pos != -1) {
tmp = m_subject.mid(pos, len);
pos = tmp.indexOf('/');