Commit 25d9df5c authored by Ahmad Samir's avatar Ahmad Samir
Browse files

Port QRegExp to QRegularExpression

Summary:
In kgpgOptions::updateWidgets(), I assumed "[0-9A-Fa-F]" had a typo and
replaced the last "F" with "f".

Port QRegExp::exactMatch() with QRegularExpression::anchoredPattern(),
except in KGpgGroupNodePrivate::groupPattern() as the pattern is already
anchored with ^ and $.

Test Plan: make && ctest

Reviewers: dakon

Reviewed By: dakon

Subscribers: kde-utils-devel

Differential Revision: https://phabricator.kde.org/D27177
parent 911fbdeb
......@@ -29,6 +29,7 @@
#include <QFile>
#include <QRegularExpression>
#include <QStringList>
#include <QTextStream>
......@@ -50,7 +51,7 @@ public:
*/
int findGroupEntry(QFile &conffile, QTextStream &stream, QStringList &lines);
static const QRegExp &groupPattern();
static const QRegularExpression &groupPattern();
static const QString &groupTag();
};
......@@ -79,7 +80,7 @@ KGpgGroupNodePrivate::findGroupEntry(QFile &conffile, QTextStream &stream, QStri
i++;
QString parsedLine = rawLine.simplified().section(QLatin1Char('#'), 0, 0);
if (groupPattern().exactMatch(parsedLine)) {
if (groupPattern().match(parsedLine).hasMatch()) {
// remove "group "
parsedLine.remove(0, 6);
if (parsedLine.startsWith(m_name)) {
......@@ -102,10 +103,10 @@ KGpgGroupNodePrivate::findGroupEntry(QFile &conffile, QTextStream &stream, QStri
return index;
}
const QRegExp &
const QRegularExpression &
KGpgGroupNodePrivate::groupPattern()
{
static const QRegExp groupre(QLatin1String("^group [^ ]+ ?= ?([0-9a-fA-F]{8,} ?)*$"));
static const QRegularExpression groupre(QStringLiteral("^group [^ ]+ ?= ?([0-9a-fA-F]{8,} ?)*$"));
return groupre;
}
......
......@@ -32,6 +32,7 @@
#include <KLocalizedString>
#include <KMessageBox>
#include <QCursor>
#include <QRegularExpression>
KeyServer::KeyServer(QWidget *parent, KGpgItemModel *model, const bool autoclose)
: QDialog(parent),
......@@ -197,7 +198,7 @@ void KeyServer::slotSearch()
return;
m_resultmodel.resetSourceModel();
m_resultmodel.setFilterRegExp(QRegExp());
m_resultmodel.setFilterRegularExpression(QRegularExpression());
m_resultmodel.setFilterByValidity(true);
m_dialogserver = new QDialog(this);
......@@ -340,7 +341,7 @@ QStringList KeyServer::getServerList()
{
QStringList serverList(KGpgSettings::keyServers()); // From kgpg config
if (!serverList.isEmpty()) {
serverList.replaceInStrings(QRegExp(QLatin1String(" .*")), QString()); // Remove kde 3.5 (Default) tag.
serverList.replaceInStrings(QRegularExpression(QStringLiteral(" .*")), QString()); // Remove kde 3.5 (Default) tag.
const QString defaultServer(serverList.takeFirst());
std::sort(serverList.begin(), serverList.end());
serverList.prepend(defaultServer);
......@@ -368,7 +369,7 @@ void KeyServer::slotSetKeyserver(const QString &server)
void KeyServer::slotSetFilterString(const QString &expression)
{
m_resultmodel.setFilterRegExp(QRegExp(expression, Qt::CaseInsensitive, QRegExp::RegExp2));
m_resultmodel.setFilterRegularExpression(QRegularExpression(expression, QRegularExpression::CaseInsensitiveOption));
slotUpdateLabelOnFilterChange();
}
......
......@@ -106,6 +106,7 @@
#include <QPrintDialog>
#include <QPrinter>
#include <QProcess>
#include <QRegularExpression>
#include <QStatusBar>
#include <QUrl>
#include <QWidget>
......@@ -1439,7 +1440,7 @@ void KeysManager::slotexport()
sname.prepend(QDir::homePath() + QLatin1Char( '/' ));
QStringList serverList(KGpgSettings::keyServers());
serverList.replaceInStrings(QRegExp(QLatin1String(" .*")), QString()); // Remove kde 3.5 (Default) tag.
serverList.replaceInStrings(QRegularExpression(QStringLiteral(" .*")), QString()); // Remove kde 3.5 (Default) tag.
if (!serverList.isEmpty()) {
QString defaultServer = serverList.takeFirst();
std::sort(serverList.begin(), serverList.end());
......
......@@ -39,6 +39,7 @@
#include <QInputDialog>
#include <QTextStream>
#include <QVBoxLayout>
#include <QRegularExpression>
#include <QStandardPaths>
using namespace KgpgCore;
......@@ -81,7 +82,7 @@ kgpgOptions::kgpgOptions(QWidget *parent, KGpgItemModel *model)
// Remove everything after a whitespace. This will normally be
// ' (Default)' from KDE 3.x.x
serverList.replaceInStrings(QRegExp( QLatin1String( " .*") ), QString() );
serverList.replaceInStrings(QRegularExpression(QStringLiteral(" .*")), QString());
m_serverModel->setStringList(serverList);
// if the server from GnuPG config is set and is not in the list of servers put it there
......@@ -291,10 +292,10 @@ void kgpgOptions::updateWidgets()
if (!fileEncryptionKey.isEmpty()) {
int idpos = m_page1->file_key->findText(fileEncryptionKey);
if (idpos == -1) {
idpos = fileEncryptionKey.indexOf(QRegExp( QLatin1String( "([0-9A-Fa-F]{8})+" )));
idpos = fileEncryptionKey.indexOf(QRegularExpression(QStringLiteral("([0-9A-Fa-f]{8})+")));
if (idpos >= 0) {
QString fileId = fileEncryptionKey.mid(idpos);
idpos = fileId.indexOf(QRegExp( QLatin1String( "[^a-fA-F0-9]" )));
idpos = fileId.indexOf(QRegularExpression(QStringLiteral("[^a-fA-F0-9]")));
if (idpos >= 0) {
fileId.truncate(idpos);
fileId.chop(fileId.length() % 8);
......
......@@ -19,6 +19,7 @@
#include <QDateTime>
#include <QRegularExpression>
#include <QScopedPointer>
#include <QString>
#include <QStringList>
......@@ -97,11 +98,12 @@ void
SearchResult::addUid(const QString &id)
{
Q_ASSERT(m_emails.count() == m_names.count());
QRegExp hasmail( QLatin1String( "(.*) <(.*)>" ));
const QRegularExpression hasmail(QRegularExpression::anchoredPattern(QStringLiteral("(.*) <(.*)>")));
if (hasmail.exactMatch(id)) {
m_names.append(hasmail.capturedTexts().at(1));
m_emails.append(hasmail.capturedTexts().at(2));
const QRegularExpressionMatch match = hasmail.match(id);
if (match.hasMatch()) {
m_names.append(match.captured(1));
m_emails.append(match.captured(2));
} else {
m_names.append(id);
m_emails.append(QString());
......@@ -178,14 +180,15 @@ KGpgSearchResultModelPrivate::urlDecode(const QString &line)
return line;
QByteArray tmp(line.toLatin1());
const QRegExp hex( QLatin1String( "[A-F0-9]{2}" )); // URL-encoding uses only uppercase
const QRegularExpression hex(
QRegularExpression::anchoredPattern(QStringLiteral("[A-F0-9]{2}"))); // URL-encoding uses only uppercase
int pos = -1; // avoid error if '%' is URL-encoded
while ((pos = tmp.indexOf("%", pos + 1)) >= 0) {
const QByteArray hexnum(tmp.mid(pos + 1, 2));
// the input is not properly URL-encoded, so assume it does not need to be decoded at all
if (!hex.exactMatch(QLatin1String( hexnum )))
if (!hex.match(QLatin1String(hexnum)).hasMatch())
return line;
char n[2];
......
......@@ -22,6 +22,7 @@
#include "core/kgpgkey.h"
#include <QLocale>
#include <QRegularExpression>
#include <KLocalizedString>
......@@ -63,8 +64,8 @@ SelectKeyProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_
return false;
// there is probably a better place to do this
QRegExp rx = filterRegExp();
rx.setCaseSensitivity(Qt::CaseInsensitive);
QRegularExpression rx = filterRegularExpression();
rx.setPatternOptions(rx.patternOptions() | QRegularExpression::CaseInsensitiveOption);
if (l->getName().contains(rx))
return true;
......
......@@ -19,7 +19,7 @@
#include <KIO/Job>
#include <QRegExp>
#include <QRegularExpression>
#include <QTemporaryFile>
KGpgTextOrFileTransaction::KGpgTextOrFileTransaction(QObject *parent, const QString &text, const bool allowChaining)
......@@ -45,7 +45,7 @@ KGpgTextOrFileTransaction::setText(const QString &text)
m_text = text;
cleanUrls();
int begin = text.indexOf(QRegExp(QLatin1String("^(.*\n)?-----BEGIN PGP [A-Z ]*-----\r?\n")));
int begin = text.indexOf(QRegularExpression(QStringLiteral("^(.*\n)?-----BEGIN PGP [A-Z ]*-----\r?\n")));
if (begin < 0)
return;
......
......@@ -18,6 +18,7 @@
#include "model/kgpgitemmodel.h"
#include <QLocale>
#include <QRegularExpression>
#include <KLocalizedString>
......@@ -106,7 +107,7 @@ KGpgVerify::getReport(const QStringList &log, const KGpgItemModel *model)
// newer versions of GnuPG emit both VALIDSIG and GOODSIG
// for a good signature. Since VALIDSIG has more information
// we use that.
const QRegExp validsig(QLatin1String("^\\[GNUPG:\\] VALIDSIG([ ]+[^ ]+){10,}.*$"));
const QRegularExpression validsig(QStringLiteral("^\\[GNUPG:\\] VALIDSIG([ ]+[^ ]+){10,}.*$"));
const bool useGoodSig = (model == nullptr) || (log.indexOf(validsig) == -1);
QString sigtime; // timestamp of signature creation
......
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