diff --git a/autotests/kurifiltertest.cpp b/autotests/kurifiltertest.cpp --- a/autotests/kurifiltertest.cpp +++ b/autotests/kurifiltertest.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include @@ -111,7 +111,7 @@ if (!expectedResult.isEmpty()) { // Hack for other locales than english, normalize google hosts to google.com - cmd.replace(QRegExp(QStringLiteral("www\\.google\\.[^/]*/")), QStringLiteral("www.google.com/")); + cmd.replace(QRegularExpression(QStringLiteral("www\\.google\\.[^/]*/")), QStringLiteral("www.google.com/")); if (cmd != expectedResult) { qWarning() << a; QCOMPARE(cmd, expectedResult); diff --git a/src/core/kprotocolmanager.cpp b/src/core/kprotocolmanager.cpp --- a/src/core/kprotocolmanager.cpp +++ b/src/core/kprotocolmanager.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -900,9 +901,9 @@ // Clean up unnecessary separators that could be left over from the // possible keyword removal above... - agentStr.replace(QRegExp(QL1S("[(]\\s*[;]\\s*")), QStringLiteral("(")); - agentStr.replace(QRegExp(QL1S("[;]\\s*[;]\\s*")), QStringLiteral("; ")); - agentStr.replace(QRegExp(QL1S("\\s*[;]\\s*[)]")), QStringLiteral(")")); + agentStr.replace(QRegularExpression(QStringLiteral("[(]\\s*[;]\\s*")), QStringLiteral("(")); + agentStr.replace(QRegularExpression(QStringLiteral("[;]\\s*[;]\\s*")), QStringLiteral("; ")); + agentStr.replace(QRegularExpression(QStringLiteral("\\s*[;]\\s*[)]")), QStringLiteral(")")); } else { agentStr.remove(QStringLiteral("%osname%")); agentStr.remove(QStringLiteral("%osversion%")); diff --git a/src/core/krecentdocument.cpp b/src/core/krecentdocument.cpp --- a/src/core/krecentdocument.cpp +++ b/src/core/krecentdocument.cpp @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include @@ -101,7 +101,7 @@ } QString openStr = url.toDisplayString(); - openStr.replace(QRegExp(QStringLiteral("\\$")), QStringLiteral("$$")); // Desktop files with type "Link" are $-variable expanded + openStr.replace(QRegularExpression(QStringLiteral("\\$")), QStringLiteral("$$")); // Desktop files with type "Link" are $-variable expanded // qDebug() << "KRecentDocument::add for " << openStr; KConfigGroup config = KSharedConfig::openConfig()->group(QByteArray("RecentDocuments")); diff --git a/src/ioslaves/help/kio_help.cpp b/src/ioslaves/help/kio_help.cpp --- a/src/ioslaves/help/kio_help.cpp +++ b/src/ioslaves/help/kio_help.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include @@ -300,7 +299,7 @@ if (!anchor.isEmpty()) { int index = 0; while (true) { - index = mParsed.indexOf(QRegExp(QStringLiteral(" #include #include -#include +#include #include #include #include @@ -164,9 +164,9 @@ static QString sanitizeCustomHTTPHeader(const QString &_header) { QString sanitizedHeaders; - const QStringList headers = _header.split(QRegExp(QStringLiteral("[\r\n]"))); + const QVector headers = _header.splitRef(QRegularExpression(QStringLiteral("[\r\n]"))); - for (const QString &header : headers) { + for (const QStringRef &header : headers) { // Do not allow Request line to be specified and ignore // the other HTTP headers. if (!header.contains(QLatin1Char(':')) || @@ -3280,7 +3280,7 @@ rel = rel.mid(5, rel.length() - 6); if (rel.toLower() == QLatin1String("pageservices")) { //### the remove() part looks fishy! - QString url = link[0].remove(QRegExp(QStringLiteral("[<>]"))).trimmed(); + QString url = link[0].remove(QRegularExpression(QStringLiteral("[<>]"))).trimmed(); setMetaData(QStringLiteral("PageServices"), url); } } @@ -3296,12 +3296,12 @@ .split(QLatin1Char('='), QString::SkipEmptyParts); if (policy.count() == 2) { if (policy[0].toLower() == QLatin1String("policyref")) { - policyrefs << policy[1].remove(QRegExp(QStringLiteral("[\")\']"))).trimmed(); + policyrefs << policy[1].remove(QRegularExpression(QStringLiteral("[\")\']"))).trimmed(); } else if (policy[0].toLower() == QLatin1String("cp")) { // We convert to cp\ncp\ncp\n[...]\ncp to be consistent with // other metadata sent in strings. This could be a bit more // efficient but I'm going for correctness right now. - const QString s = policy[1].remove(QRegExp(QStringLiteral("[\")\']"))); + const QString s = policy[1].remove(QRegularExpression(QStringLiteral("[\")\']"))); const QStringList cps = s.split(QLatin1Char(' '), QString::SkipEmptyParts); compact << cps; } @@ -3367,7 +3367,7 @@ if (tIt.hasNext()) { // Now we have to check to see what is offered for the upgrade QString offered = toQString(tIt.next()); - upgradeOffers = offered.split(QRegExp(QStringLiteral("[ \n,\r\t]")), QString::SkipEmptyParts); + upgradeOffers = offered.split(QRegularExpression(QStringLiteral("[ \n,\r\t]")), QString::SkipEmptyParts); } for (const QString &opt : qAsConst(upgradeOffers)) { if (opt == QLatin1String("TLS/1.0")) { diff --git a/src/ioslaves/http/kcookiejar/kcookiejar.cpp b/src/ioslaves/http/kcookiejar/kcookiejar.cpp --- a/src/ioslaves/http/kcookiejar/kcookiejar.cpp +++ b/src/ioslaves/http/kcookiejar/kcookiejar.cpp @@ -43,7 +43,7 @@ #include #include -#include +#include #include #include #include @@ -629,7 +629,8 @@ return; } // Return numeric IPv4 addresses as is... - if (_fqdn[0] >= QL1C('0') && _fqdn[0] <= QL1C('9') && _fqdn.indexOf(QRegExp(QStringLiteral(IP_ADDRESS_EXPRESSION))) > -1) { + if (_fqdn[0] >= QL1C('0') && _fqdn[0] <= QL1C('9') + && _fqdn.indexOf(QRegularExpression(QStringLiteral(IP_ADDRESS_EXPRESSION))) > -1) { _domains.append(_fqdn); return; } diff --git a/src/kpac/script.cpp b/src/kpac/script.cpp --- a/src/kpac/script.cpp +++ b/src/kpac/script.cpp @@ -21,7 +21,7 @@ #include "script.h" #include -#include +#include #include #include @@ -314,8 +314,9 @@ // @returns true if @p str matches the shell @p pattern Q_INVOKABLE QJSValue ShExpMatch(QString str, QString patternStr) { - QRegExp pattern(patternStr, Qt::CaseSensitive, QRegExp::Wildcard); - return QJSValue(pattern.exactMatch(str)); + const QRegularExpression pattern(QRegularExpression::anchoredPattern( + QRegularExpression::wildcardToRegularExpression(patternStr))); + return QJSValue(pattern.match(str).hasMatch()); } // weekdayRange(day [, "GMT" ]) diff --git a/src/urifilters/localdomain/localdomainurifilter.h b/src/urifilters/localdomain/localdomainurifilter.h --- a/src/urifilters/localdomain/localdomainurifilter.h +++ b/src/urifilters/localdomain/localdomainurifilter.h @@ -23,7 +23,7 @@ #include -#include +#include class QHostInfo; class QEventLoop; @@ -45,7 +45,7 @@ private: bool exists(const QString &) const; - QRegExp m_hostPortPattern; + QRegularExpression m_hostPortPattern; }; #endif diff --git a/src/urifilters/localdomain/localdomainurifilter.cpp b/src/urifilters/localdomain/localdomainurifilter.cpp --- a/src/urifilters/localdomain/localdomainurifilter.cpp +++ b/src/urifilters/localdomain/localdomainurifilter.cpp @@ -30,8 +30,6 @@ #define QL1C(x) QLatin1Char(x) #define QL1S(x) QLatin1String(x) -#define HOSTPORT_PATTERN "[a-zA-Z0-9][a-zA-Z0-9+-]*(?:\\:[0-9]{1,5})?(?:/[\\w:@&=+$,-.!~*'()]*)*" - namespace { QLoggingCategory category("org.kde.kurifilter-localdomain", QtWarningMsg); } @@ -42,8 +40,9 @@ */ LocalDomainUriFilter::LocalDomainUriFilter(QObject *parent, const QVariantList & /*args*/) : KUriFilterPlugin(QStringLiteral("localdomainurifilter"), parent) - , m_hostPortPattern(QL1S(HOSTPORT_PATTERN)) { + m_hostPortPattern = QRegularExpression(QRegularExpression::anchoredPattern( + QStringLiteral("[a-zA-Z0-9][a-zA-Z0-9+-]*(?:\\:[0-9]{1,5})?(?:/[\\w:@&=+$,-.!~*'()]*)*"))); } bool LocalDomainUriFilter::filterUri(KUriFilterData &data) const @@ -54,7 +53,7 @@ // When checking for local domain just validate it is indeed a local domain, // but do not modify the hostname! See bug# if ((protocol.isEmpty() || !KProtocolInfo::isKnownProtocol(protocol)) - && m_hostPortPattern.exactMatch(data.typedString())) { + && m_hostPortPattern.match(data.typedString()).hasMatch()) { QString host(data.typedString().left(data.typedString().indexOf(QL1C('/')))); const int pos = host.indexOf(QL1C(':')); if (pos > -1) { diff --git a/src/urifilters/shorturi/kshorturifilter.h b/src/urifilters/shorturi/kshorturifilter.h --- a/src/urifilters/shorturi/kshorturifilter.h +++ b/src/urifilters/shorturi/kshorturifilter.h @@ -24,7 +24,7 @@ #define KSHORTURIFILTER_H #include -#include +#include #include #include @@ -98,13 +98,13 @@ } URLHint(const QString &r, const QString &p, KUriFilterData::UriTypes t = KUriFilterData::NetProtocol) - : regexp(QRegExp(r)) + : hintRe(r) , prepend(p) , type(t) { } - QRegExp regexp; // if this matches, then... + QRegularExpression hintRe; // if this matches, then... QString prepend; // ...prepend this to the url KUriFilterData::UriTypes type; }; diff --git a/src/urifilters/shorturi/kshorturifilter.cpp b/src/urifilters/shorturi/kshorturifilter.cpp --- a/src/urifilters/shorturi/kshorturifilter.cpp +++ b/src/urifilters/shorturi/kshorturifilter.cpp @@ -432,12 +432,11 @@ // Short url matches if (!cmd.contains(QLatin1Char(' '))) { - // Okay this is the code that allows users to supply custom matches for - // specific URLs using Qt's regexp class. This is hard-coded for now. - // TODO: Make configurable at some point... + // Okay this is the code that allows users to supply custom matches for specific + // URLs using Qt's QRegularExpression class. for (const URLHint &hint : qAsConst(m_urlHints)) { qCDebug(category) << "testing regexp for" << hint.prepend; - if (hint.regexp.indexIn(cmd) == 0) { + if (hint.hintRe.match(cmd).capturedStart() == 0) { const QString cmdStr = hint.prepend + cmd; QUrl url(cmdStr); qCDebug(category) << "match - prepending" << hint.prepend << "->" << cmdStr << "->" << url; diff --git a/src/widgets/jobuidelegate.cpp b/src/widgets/jobuidelegate.cpp --- a/src/widgets/jobuidelegate.cpp +++ b/src/widgets/jobuidelegate.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include "kio/scheduler.h" @@ -216,7 +217,7 @@ QString path = url.path(); // HACK (#98983): remove "0-foo". Note that it works better than // displaying KFileItem::name(), for files under a subdir. - path.remove(QRegExp(QStringLiteral("^/[0-9]*-"))); + path.remove(QRegularExpression(QStringLiteral("^/[0-9]*-"))); prettyList.append(path); } else { prettyList.append(url.toDisplayString(QUrl::PreferLocalFile)); diff --git a/src/widgets/kurlcompletion.cpp b/src/widgets/kurlcompletion.cpp --- a/src/widgets/kurlcompletion.cpp +++ b/src/widgets/kurlcompletion.cpp @@ -30,7 +30,7 @@ #include #include -#include +#include #include #include #include @@ -496,11 +496,11 @@ } // Look for a protocol in 'url' - QRegExp protocol_regex = QRegExp(QStringLiteral("^(?![A-Za-z]:)[^/\\s\\\\]*:")); + const QRegularExpression protocol_regex(QStringLiteral("^(?![A-Za-z]:)[^/\\s\\\\]*:")); // Assume "file:" or whatever is given by 'cwd' if there is // no protocol. (QUrl does this only for absolute paths) - if (protocol_regex.indexIn(url_copy) == 0) { + if (protocol_regex.match(url_copy).hasMatch()) { m_kurl = QUrl(url_copy); m_isURL = true; } else { // relative path or ~ or $something diff --git a/src/widgets/previewjob.cpp b/src/widgets/previewjob.cpp --- a/src/widgets/previewjob.cpp +++ b/src/widgets/previewjob.cpp @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include @@ -339,7 +339,7 @@ QMap::ConstIterator pluginIt = mimeMap.constFind(mimeType); if (pluginIt == mimeMap.constEnd()) { QString groupMimeType = mimeType; - groupMimeType.replace(QRegExp(QStringLiteral("/.*")), QStringLiteral("/*")); + groupMimeType.replace(QRegularExpression(QStringLiteral("/.*")), QStringLiteral("/*")); pluginIt = mimeMap.constFind(groupMimeType); if (pluginIt == mimeMap.constEnd()) {