Commit 0b7faa91 authored by Ahmad Samir's avatar Ahmad Samir Committed by Ingo Klöcker
Browse files

Port from QRegExp to QRegularExpression

Port QRegExp::exactMatch() by using QRegularExpression::anchordPattern().
parent 3b92b040
......@@ -20,7 +20,6 @@
#include <KLocalizedString>
#include <QSaveFile>
#include <QRegExp>
#include <QThread>
#include <QMutex>
#include <QMutexLocker>
......@@ -276,19 +275,21 @@ QString change_trust_file(const QString &trustListFile, const QString &key, Key:
qCDebug(KLEOPATRA_LOG) << qPrintable(key) << " -> " << qPrintable(keyColon);
// ( 1) ( 2 ) ( 3 )( 4)
QRegExp rx(QLatin1String("\\s*(!?)\\s*([a-fA-F0-9]{40}|(?:[a-fA-F0-9]{2}:){19}[a-fA-F0-9]{2})\\s*([SsPp*])(.*)"));
// ( 1) ( 2 ) ( 3 )( 4)
static const char16_t pattern[] = uR"(\s*(!?)\s*([a-fA-F0-9]{40}|(?:[a-fA-F0-9]{2}:){19}[a-fA-F0-9]{2})\s*([SsPp*])(.*))";
static const QRegularExpression rx(QRegularExpression::anchoredPattern(pattern));
bool found = false;
for (const QByteArray &rawLine : std::as_const(trustListFileContents)) {
const QString line = QString::fromLatin1(rawLine.data(), rawLine.size());
if (!rx.exactMatch(line)) {
const QRegularExpressionMatch match = rx.match(line);
if (!match.hasMatch()) {
qCDebug(KLEOPATRA_LOG) << "line \"" << rawLine.data() << "\" does not match";
out.write(rawLine + '\n');
continue;
}
const QString cap2 = rx.cap(2);
const QString cap2 = match.captured(2);
if (cap2 != key && cap2 != keyColon) {
qCDebug(KLEOPATRA_LOG) << qPrintable(key) << " != "
<< qPrintable(cap2) << " != "
......@@ -297,9 +298,9 @@ QString change_trust_file(const QString &trustListFile, const QString &key, Key:
continue;
}
found = true;
const bool disabled = rx.cap(1) == QLatin1Char('!');
const QByteArray flags = rx.cap(3).toLatin1();
const QByteArray rests = rx.cap(4).toLatin1();
const bool disabled = match.capturedView(1) == QLatin1Char('!');
const QByteArray flags = match.captured(3).toLatin1();
const QByteArray rests = match.captured(4).toLatin1();
if (trust == Key::Ultimate)
if (!disabled) { // unchanged
out.write(rawLine + '\n');
......
......@@ -30,7 +30,6 @@
#include <QMap>
#include <QPointer>
#include <QRegExp>
#include <QFileInfo>
#include <algorithm>
......@@ -202,9 +201,13 @@ bool ExportCertificateCommand::Private::requestFileNames(GpgME::Protocol protoco
/* If the user has already selected a PGP file name then use that as basis
* for a proposal for the S/MIME file. */
proposedFileName = fileNames[GpgME::OpenPGP];
proposedFileName.replace(QRegExp(QStringLiteral(".asc$")), QStringLiteral(".pem"));
proposedFileName.replace(QRegExp(QStringLiteral(".gpg$")), QStringLiteral(".der"));
proposedFileName.replace(QRegExp(QStringLiteral(".pgp$")), QStringLiteral(".der"));
const int idx = proposedFileName.size() - 4;
if (proposedFileName.endsWith(QLatin1String(".asc"))) {
proposedFileName.replace(idx, 4, QLatin1String(".pem"));
}
if (proposedFileName.endsWith(QLatin1String(".gpg")) || proposedFileName.endsWith(QLatin1String(".pgp"))) {
proposedFileName.replace(idx, 4, QLatin1String(".der"));
}
}
}
......
......@@ -46,7 +46,7 @@
#include <KMessageBox>
#include "kleopatra_debug.h"
#include <QRegExp>
#include <QRegularExpression>
#include <vector>
#include <map>
......@@ -303,8 +303,8 @@ void LookupCertificatesCommand::Private::slotSearchTextChanged(const QString &st
}
if (protocol != GpgME::CMS) {
const QRegExp rx(QLatin1String("(?:0x|0X)?[0-9a-fA-F]{6,}"));
if (rx.exactMatch(query) && !str.startsWith(QLatin1String("0x"), Qt::CaseInsensitive)) {
static const QRegularExpression rx(QRegularExpression::anchoredPattern(QLatin1String("(?:0x|0X)?[0-9a-fA-F]{6,}")));
if (rx.match(query).hasMatch() && !str.startsWith(QLatin1String("0x"), Qt::CaseInsensitive)) {
qCDebug(KLEOPATRA_LOG) << "Adding 0x prefix to query";
startKeyListJob(OpenPGP, QStringLiteral("0x") + str);
} else {
......
......@@ -47,7 +47,7 @@
#include <QPointer>
#include <QFileInfo>
#include <QStringList>
#include <QRegExp>
#include <QRegularExpression>
#include <QWidget>
#include <QCoreApplication>
......@@ -356,13 +356,14 @@ private:
AssuanServerConnection::Private &conn = *static_cast<AssuanServerConnection::Private *>(assuan_get_pointer(ctx_));
const QString str = QString::fromUtf8(line);
QRegExp rx(QLatin1String("(\\d+)(?:\\s+(.*))?"));
if (!rx.exactMatch(str)) {
static const QRegularExpression rx(QRegularExpression::anchoredPattern(uR"((\d+)(?:\s+(.*))?)"));
const QRegularExpressionMatch match = rx.match(str);
if (!match.hasMatch()) {
static const QString errorString = i18n("Parse error");
return assuan_process_done_msg(ctx_, gpg_error(GPG_ERR_ASS_SYNTAX), errorString);
}
bool ok = false;
if (const qulonglong id = rx.cap(1).toULongLong(&ok)) {
if (const qulonglong id = match.captured(1).toULongLong(&ok)) {
if (ok && id <= std::numeric_limits<unsigned int>::max()) {
SessionDataHandler::instance()->enterSession(id);
conn.sessionId = id;
......@@ -371,8 +372,10 @@ private:
return assuan_process_done_msg(ctx_, gpg_error(GPG_ERR_ASS_SYNTAX), errorString);
}
}
if (!rx.cap(2).isEmpty()) {
conn.sessionTitle = rx.cap(2);
const QString cap2 = match.captured(2);
if (!cap2.isEmpty()) {
conn.sessionTitle = cap2;
}
qCDebug(KLEOPATRA_LOG) << "session_handler: "
<< "id=" << static_cast<unsigned long>(conn.sessionId)
......
......@@ -140,7 +140,7 @@ static void parse_command(QString cmdline, const QString &id, const QString &whi
l = KShell::splitArgs(cmdline, KShell::AbortOnMeta | KShell::TildeExpand, &errors);
l = l.replaceInStrings(QStringLiteral("__files_go_here__"), FILE_PLACEHOLDER);
l = l.replaceInStrings(QStringLiteral("__file7Bit_go_here__"), FILE_PLACEHOLDER_7BIT);
if (l.indexOf(QRegExp(QLatin1String(".*__path_goes_here__.*"))) >= 0) {
if (l.indexOf(QRegularExpression(QLatin1String(".*__path_goes_here__.*"))) >= 0) {
l = l.replaceInStrings(QStringLiteral("__path_goes_here__"), ArchiveDefinition::installPath());
}
if (errors == KShell::BadQuoting) {
......@@ -299,7 +299,7 @@ private:
* the chars and replace them by _ to avoid completely broken
* folder names when unpacking. This is only relevant for the
* unpacked folder and does not effect files in the archive. */
const QRegExp non7Bit(QStringLiteral("[^\\x{0000}-\\x{007F}]"));
const QRegularExpression non7Bit(QLatin1String(R"([^\x{0000}-\x{007F}])"));
QString underscore_filename = file;
underscore_filename.replace(non7Bit, QStringLiteral("_"));
copy.replaceInStrings(FILE_PLACEHOLDER_7BIT, underscore_filename);
......
......@@ -574,8 +574,8 @@ void FileOutput::doFinalize()
* rename and remove. So if we can't find our temporary file we try
* to workaround that bug. */
qCDebug(KLEOPATRA_LOG) << "failure to find " << tmpFileName;
if (tmpFileName.startsWith(QStringLiteral("UNC"))) {
tmpFileName.replace(QRegExp(QStringLiteral("^UNC")), QStringLiteral("/"));
if (tmpFileName.startsWith(QLatin1String("UNC"))) {
tmpFileName.replace(0, strlen("UNC"), QLatin1Char('/'));
qtbug83365_workaround = true;
}
const QFileInfo fi2(tmpFileName);
......
......@@ -291,7 +291,7 @@ static QString qt_create_commandline(const QString &program, const QStringList &
for (int i=0; i<arguments.size(); ++i) {
QString tmp = arguments.at(i);
// Quotes are escaped and their preceding backslashes are doubled.
tmp.replace(QRegExp(QLatin1String("(\\\\*)\"")), QLatin1String("\\1\\1\\\""));
tmp.replace(QRegularExpression(QLatin1String(R"((\\*)")")), QLatin1String(R"(\1\1\")"));
if (tmp.isEmpty() || tmp.contains(QLatin1Char(' ')) || tmp.contains(QLatin1Char('\t'))) {
// The argument must not end with a \ since this would be interpreted
// as escaping the quote -- rather put the \ behind the quote: e.g.
......
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