Unverified Commit 5fe6acea authored by Carl Schwan's avatar Carl Schwan 🚴
Browse files

Remove some QRegExp usage



Signed-off-by: Carl Schwan's avatarCarl Schwan <carl@carlschwan.eu>
parent 6b5d6236
......@@ -10,6 +10,7 @@
#include <QByteArray>
#include <QDebug>
#include <QList>
#include <QRegularExpression>
#include <QSysInfo>
#include <QTextCodec>
#include <QTextDocument>
......@@ -85,22 +86,17 @@ QString replacePrefixes(const QString &str, const QStringList &prefixRegExps, co
// 1. is anchored to the beginning of str (sans whitespace)
// 2. matches at least one of the part regexps in prefixRegExps
const QString bigRegExp = QStringLiteral("^(?:\\s+|(?:%1))+\\s*").arg(prefixRegExps.join(QStringLiteral(")|(?:")));
QRegExp rx(bigRegExp, Qt::CaseInsensitive);
if (!rx.isValid()) {
qWarning() << "bigRegExp = \"" << bigRegExp << "\"\n"
<< "prefix regexp is invalid!";
qWarning() << "Error: " << rx.errorString() << rx;
Q_ASSERT(false);
return str;
}
static QRegularExpression regex(bigRegExp, QRegularExpression::CaseInsensitiveOption);
Q_ASSERT(regex.isValid());
QString tmp = str;
// We expect a match at the beginning of the string
if (rx.indexIn(tmp) == 0) {
return tmp.replace(0, rx.matchedLength(), newPrefix + QLatin1String(" "));
const auto match = regex.match(tmp);
if (match.hasMatch()) {
return tmp.replace(0, match.captured(0).length(), newPrefix + QLatin1Char(' '));
}
// No match, we just prefix the newPrefix
return newPrefix + QStringLiteral(" ") + str;
return newPrefix + QLatin1Char(' ') + str;
}
const QStringList getForwardPrefixes()
......@@ -251,9 +247,9 @@ static QString stripSignature(const QString &msg)
qWarning() << "Message contains CRLF, but shouldn't: " << msg;
Q_ASSERT(false);
}
const QRegExp sbDelimiterSearch = QRegExp(QLatin1String("(^|\n)[> ]*-- \n"));
const QRegExp sbDelimiterSearch(QLatin1String("(^|\n)[> ]*-- \n"));
// The regular expression to look for prefix change
const QRegExp commonReplySearch = QRegExp(QLatin1String("^[ ]*>"));
const QRegExp commonReplySearch(QLatin1String("^[ ]*>"));
QString res = msg;
int posDeletingStart = 1; // to start looking at 0
......
......@@ -21,6 +21,7 @@
#include <KCharsets>
#include <QByteArray>
#include <QMimeDatabase>
#include <QRegularExpression>
#include <QTextCodec>
#include <QTextStream>
#include <QUrl>
......@@ -297,11 +298,11 @@ void ObjectTreeParser::importCertificates()
QString ObjectTreeParser::resolveCidLinks(const QString &html)
{
auto text = html;
const auto regex = QRegExp(QLatin1String("(src)\\s*=\\s*(\"|')(cid:[^\"']+)\\2"));
int pos = 0;
while ((pos = regex.indexIn(text, pos)) != -1) {
const auto link = QUrl(regex.cap(3));
pos += regex.matchedLength();
static const auto regex = QRegularExpression(QLatin1String("(src)\\s*=\\s*(\"|')(cid:[^\"']+)\\2"));
auto it = regex.globalMatch(text);
while (it.hasNext()) {
const auto match = it.next();
const auto link = QUrl(match.captured(3));
auto cid = link.path();
auto mailMime = const_cast<KMime::Content *>(find([=](KMime::Content *content) {
if (!content || !content->contentID(false)) {
......@@ -324,7 +325,7 @@ QString ObjectTreeParser::resolveCidLinks(const QString &html)
qWarning() << "Attachment is empty.";
continue;
}
text.replace(regex.cap(0), QString::fromLatin1("src=\"data:%1;base64,%2\"").arg(mimetype, QString::fromLatin1(data.toBase64())));
text.replace(match.captured(0), QString::fromLatin1("src=\"data:%1;base64,%2\"").arg(mimetype, QString::fromLatin1(data.toBase64())));
}
} else {
qWarning() << "Failed to find referenced attachment: " << cid;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment