Commit ec6e61ab authored by Ahmad Samir's avatar Ahmad Samir Committed by Volker Krause

Port QRegExp to QRegularExpression

parent 761bf1df
Pipeline #30997 passed with stage
in 59 minutes and 11 seconds
......@@ -37,7 +37,7 @@ FilterActionRewriteHeader::FilterActionRewriteHeader(QObject *parent)
bool FilterActionRewriteHeader::isEmpty() const
{
return mParameter.isEmpty() || mRegExp.isEmpty();
return mParameter.isEmpty() || mRegex.pattern().isEmpty();
}
QString FilterActionRewriteHeader::informationAboutNotValidAction() const
......@@ -46,7 +46,7 @@ QString FilterActionRewriteHeader::informationAboutNotValidAction() const
if (mParameter.isEmpty()) {
info = i18n("Header not defined");
}
if (mRegExp.isEmpty()) {
if (mRegex.pattern().isEmpty()) {
if (!info.isEmpty()) {
info += QLatin1Char('\n');
}
......@@ -71,7 +71,7 @@ FilterAction::ReturnCode FilterActionRewriteHeader::process(ItemContext &context
QString value = header->asUnicodeString();
const QString oldValue = value;
const QString newValue = value.replace(mRegExp, mReplacementString);
const QString newValue = value.replace(mRegex, mReplacementString);
if (newValue != oldValue) {
msg->removeHeader(param.constData());
......@@ -161,7 +161,7 @@ void FilterActionRewriteHeader::setParamWidgetValue(QWidget *paramWidget) const
KLineEdit *regExpLineEdit = paramWidget->findChild<KLineEdit *>(QStringLiteral("search"));
Q_ASSERT(regExpLineEdit);
regExpLineEdit->setText(mRegExp.pattern());
regExpLineEdit->setText(mRegex.pattern());
KLineEdit *lineEdit = paramWidget->findChild<KLineEdit *>(QStringLiteral("replace"));
Q_ASSERT(lineEdit);
......@@ -176,7 +176,7 @@ void FilterActionRewriteHeader::applyParamWidgetValue(QWidget *paramWidget)
const KLineEdit *regExpLineEdit = paramWidget->findChild<KLineEdit *>(QStringLiteral("search"));
Q_ASSERT(regExpLineEdit);
mRegExp.setPattern(regExpLineEdit->text());
mRegex.setPattern(regExpLineEdit->text());
const KLineEdit *lineEdit = paramWidget->findChild<KLineEdit *>(QStringLiteral("replace"));
Q_ASSERT(lineEdit);
......@@ -202,7 +202,7 @@ QString FilterActionRewriteHeader::argsAsString() const
{
QString result = mParameter;
result += QLatin1Char('\t');
result += mRegExp.pattern();
result += mRegex.pattern();
result += QLatin1Char('\t');
result += mReplacementString;
......@@ -223,7 +223,7 @@ void FilterActionRewriteHeader::argsFromString(const QString &argsStr)
QString result;
result = list[ 0 ];
mRegExp.setPattern(list[ 1 ]);
mRegex.setPattern(list[ 1 ]);
mReplacementString = list[ 2 ];
int index = mParameterList.indexOf(result);
......
......@@ -10,7 +10,7 @@
#include "filteractionwithstringlist.h"
#include <QRegExp>
#include <QRegularExpression>
namespace MailCommon {
//=============================================================================
......@@ -40,7 +40,7 @@ public:
Q_REQUIRED_RESULT QString informationAboutNotValidAction() const override;
private:
QRegExp mRegExp;
QRegularExpression mRegex;
QString mReplacementString;
};
}
......
......@@ -9,6 +9,8 @@
#include "mailcommon_debug.h"
#include <KProcess>
#include <KShell>
#include <QRegularExpression>
#include <QTemporaryFile>
using namespace MailCommon;
......@@ -59,16 +61,14 @@ QString FilterActionWithCommand::substituteCommandLineArgsFor(const KMime::Messa
{
QString result = mParameter;
QList<int> argList;
QRegExp r(QStringLiteral("%[0-9-]+"));
const QRegularExpression re(QStringLiteral("%([0-9-]+)"));
// search for '%n'
int start = -1;
while ((start = r.indexIn(result, start + 1)) > 0) {
const int len = r.matchedLength();
QRegularExpressionMatchIterator iter = re.globalMatch(result);
while (iter.hasNext()) {
// and save the encountered 'n' in a list.
bool ok = false;
const int n = result.midRef(start + 1, len - 1).toInt(&ok);
const int n = iter.next().captured(1).toInt(&ok);
if (ok) {
argList.append(n);
}
......@@ -139,16 +139,19 @@ void substituteMessageHeaders(const KMime::Message::Ptr &aMsg, QString &result)
{
// Replace the %{foo} with the content of the foo header field.
// If the header doesn't exist, remove the placeholder.
QRegExp header_rx(QStringLiteral("%\\{([a-z0-9-]+)\\}"), Qt::CaseInsensitive);
int idx = 0;
while ((idx = header_rx.indexIn(result, idx)) != -1) {
const KMime::Headers::Base *header = aMsg->headerByType(header_rx.cap(1).toLatin1().constData());
const QRegularExpression header_rx(QStringLiteral("%\\{([a-z0-9-]+)\\}"),
QRegularExpression::CaseInsensitiveOption);
int offset = 0;
QRegularExpressionMatch rmatch;
while (result.indexOf(header_rx, offset, &rmatch) != -1) {
const KMime::Headers::Base *header = aMsg->headerByType(rmatch.captured(1).toLatin1().constData());
QString replacement;
if (header) {
replacement = KShell::quoteArg(QString::fromLatin1(header->as7BitString()));
}
result.replace(idx, header_rx.matchedLength(), replacement);
idx += replacement.length();
const int start = rmatch.capturedStart(0);
result.replace(start, rmatch.capturedLength(0), replacement);
offset = start + replacement.size();
}
}
......
......@@ -12,7 +12,7 @@ using MailCommon::FilterLog;
#include <QDateTime>
#include <KMime/KMimeMessage>
#include <QRegExp>
#include <QRegularExpression>
#include <algorithm>
......@@ -88,14 +88,12 @@ bool SearchRuleNumerical::matchesInternal(long numericalValue, long numericalMsg
case SearchRule::FuncRegExp:
{
QRegExp regexp(contents(), Qt::CaseInsensitive);
return regexp.indexIn(msgContents) >= 0;
return msgContents.contains(QRegularExpression(contents(), QRegularExpression::CaseInsensitiveOption));
}
case SearchRule::FuncNotRegExp:
{
QRegExp regexp(contents(), Qt::CaseInsensitive);
return regexp.indexIn(msgContents) < 0;
return !msgContents.contains(QRegularExpression(contents(), QRegularExpression::CaseInsensitiveOption));
}
case FuncIsGreater:
......
......@@ -18,7 +18,7 @@ using MailCommon::FilterLog;
#include <KLocalizedString>
#include <QRegExp>
#include <QRegularExpression>
#include <algorithm>
#include <boost/bind.hpp>
......@@ -259,14 +259,12 @@ bool SearchRuleString::matchesInternal(const QString &msgContents) const
case SearchRule::FuncRegExp:
{
QRegExp regexp(contents(), Qt::CaseInsensitive);
return regexp.indexIn(msgContents) >= 0;
return msgContents.contains(QRegularExpression(contents(), QRegularExpression::CaseInsensitiveOption));
}
case SearchRule::FuncNotRegExp:
{
QRegExp regexp(contents(), Qt::CaseInsensitive);
return regexp.indexIn(msgContents) < 0;
return !msgContents.contains(QRegularExpression(contents(), QRegularExpression::CaseInsensitiveOption));
}
case SearchRule::FuncStartWith:
......
......@@ -24,6 +24,7 @@
#include <QAction>
#include <QPointer>
#include <QItemSelectionModel>
#include <QRegularExpression>
using namespace MailCommon;
......@@ -435,8 +436,8 @@ QString SnippetsManager::Private::replaceVariables(const QString &text)
int iEnd = -1;
QMap<QString, QString> tempLocalVariables(localVariables);
do {
//find the next variable by this QRegExp
iFound = text.indexOf(QRegExp(QLatin1String("\\$[A-Za-z-_0-9\\s]*\\$")), iEnd + 1);
//find the next variable by this regex
iFound = text.indexOf(QRegularExpression(QStringLiteral("\\$[A-Za-z\\-_0-9\\s]*\\$")), iEnd + 1);
if (iFound >= 0) {
iEnd = text.indexOf(QLatin1Char('$'), iFound + 1) + 1;
......
Markdown is supported
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