diff --git a/src/cmd/cmd.cpp b/src/cmd/cmd.cpp index 3a399655a..0e2699051 100644 --- a/src/cmd/cmd.cpp +++ b/src/cmd/cmd.cpp @@ -483,7 +483,7 @@ restart_sync: qCritical() << "Could not open file containing the list of unsynced folders: " << options.unsyncedfolders; } else { // filter out empty lines and comments - selectiveSyncList = QString::fromUtf8(f.readAll()).split('\n').filter(QRegExp("\\S+")).filter(QRegExp("^[^#]")); + selectiveSyncList = QString::fromUtf8(f.readAll()).split('\n').filter(QRegularExpression("\\S+")).filter(QRegularExpression("^[^#]")); for (int i = 0; i < selectiveSyncList.count(); ++i) { if (!selectiveSyncList.at(i).endsWith(QLatin1Char('/'))) { diff --git a/src/gui/creds/oauth.cpp b/src/gui/creds/oauth.cpp index 2c0e20410..aa528aa49 100644 --- a/src/gui/creds/oauth.cpp +++ b/src/gui/creds/oauth.cpp @@ -70,13 +70,14 @@ void OAuth::start() QByteArray peek = socket->peek(qMin(socket->bytesAvailable(), 4000LL)); //The code should always be within the first 4K if (peek.indexOf('\n') < 0) return; // wait until we find a \n - QRegExp rx("^GET /\\?code=([a-zA-Z0-9]+)[& ]"); // Match a /?code=... URL - if (rx.indexIn(peek) != 0) { + const QRegularExpression rx("^GET /\\?code=([a-zA-Z0-9]+)[& ]"); // Match a /?code=... URL + const auto rxMatch = rx.match(peek); + if (!rxMatch.hasMatch()) { httpReplyAndClose(socket, "404 Not Found", "404 Not Found

404 Not Found

"); return; } - QString code = rx.cap(1); // The 'code' is the first capture of the regexp + QString code = rxMatch.captured(1); // The 'code' is the first capture of the regexp QUrl requestToken = Utility::concatUrlPath(_account->url().toString(), QLatin1String("/index.php/apps/oauth2/api/v1/token")); QNetworkRequest req; diff --git a/src/gui/notificationconfirmjob.cpp b/src/gui/notificationconfirmjob.cpp index d9a7a4c34..09e147da3 100644 --- a/src/gui/notificationconfirmjob.cpp +++ b/src/gui/notificationconfirmjob.cpp @@ -56,10 +56,11 @@ bool NotificationConfirmJob::finished() const QString replyStr = reply()->readAll(); if (replyStr.contains("")) { - QRegExp rex("(\\d+)"); - if (replyStr.contains(rex)) { + const QRegularExpression rex("(\\d+)"); + const auto rexMatch = rex.match(replyStr); + if (rexMatch.hasMatch()) { // this is a error message coming back from ocs. - replyCode = rex.cap(1).toInt(); + replyCode = rexMatch.captured(1).toInt(); } } emit jobFinished(replyStr, replyCode); diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp index f8c4b68d8..6f5e2837d 100644 --- a/src/gui/sharedialog.cpp +++ b/src/gui/sharedialog.cpp @@ -96,8 +96,8 @@ ShareDialog::ShareDialog(QPointer accountState, QString ocDir(_sharePath); ocDir.truncate(ocDir.length() - fileName.length()); - ocDir.replace(QRegExp("^/*"), ""); - ocDir.replace(QRegExp("/*$"), ""); + ocDir.replace(QRegularExpression("^/*"), ""); + ocDir.replace(QRegularExpression("/*$"), ""); // Laying this out is complex because sharePath // may be in use or not. diff --git a/src/gui/syncrunfilelog.cpp b/src/gui/syncrunfilelog.cpp index cb10cef8c..6f75f53ce 100644 --- a/src/gui/syncrunfilelog.cpp +++ b/src/gui/syncrunfilelog.cpp @@ -12,7 +12,7 @@ * for more details. */ -#include +#include #include "syncrunfilelog.h" #include "common/utility.h" @@ -104,9 +104,10 @@ void SyncRunFileLog::logItem(const SyncFileItem &item) } QString ts = QString::fromLatin1(item._responseTimeStamp); if (ts.length() > 6) { - QRegExp rx(R"((\d\d:\d\d:\d\d))"); - if (ts.contains(rx)) { - ts = rx.cap(0); + const QRegularExpression rx(R"((\d\d:\d\d:\d\d))"); + const auto rxMatch = rx.match(ts); + if (rxMatch.hasMatch()) { + ts = rxMatch.captured(0); } } diff --git a/src/libsync/creds/credentialscommon.cpp b/src/libsync/creds/credentialscommon.cpp index b56b8193d..edc17ff83 100644 --- a/src/libsync/creds/credentialscommon.cpp +++ b/src/libsync/creds/credentialscommon.cpp @@ -14,7 +14,6 @@ */ #include -#include #include #include #include diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index 8fd6506b1..3fefa7cde 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -247,7 +247,7 @@ bool ProcessDirectoryJob::handleExcluded(const QString &path, const QString &loc // FIXME: move to ExcludedFiles 's regexp ? bool isInvalidPattern = false; - if (excluded == CSYNC_NOT_EXCLUDED && !_discoveryData->_invalidFilenameRx.isEmpty()) { + if (excluded == CSYNC_NOT_EXCLUDED && !_discoveryData->_invalidFilenameRx.pattern().isEmpty()) { if (path.contains(_discoveryData->_invalidFilenameRx)) { excluded = CSYNC_FILE_EXCLUDE_INVALID_CHAR; isInvalidPattern = true; diff --git a/src/libsync/discoveryphase.h b/src/libsync/discoveryphase.h index a02807341..c894cfc2a 100644 --- a/src/libsync/discoveryphase.h +++ b/src/libsync/discoveryphase.h @@ -256,7 +256,7 @@ public: AccountPtr _account; SyncOptions _syncOptions; ExcludedFiles *_excludes; - QRegExp _invalidFilenameRx; // FIXME: maybe move in ExcludedFiles + QRegularExpression _invalidFilenameRx; // FIXME: maybe move in ExcludedFiles QStringList _serverBlacklistedFiles; // The blacklist from the capabilities bool _ignoreHiddenFiles = false; std::function _shouldDiscoverLocaly; diff --git a/src/libsync/logger.cpp b/src/libsync/logger.cpp index 5e956fbab..2a90c976b 100644 --- a/src/libsync/logger.cpp +++ b/src/libsync/logger.cpp @@ -17,6 +17,7 @@ #include "config.h" #include +#include #include #include #include @@ -281,7 +282,7 @@ void Logger::enterNextLogFile() // Expire old log files and deal with conflicts QStringList files = dir.entryList(QStringList("*owncloud.log.*"), QDir::Files, QDir::Name); - QRegExp rx(R"(.*owncloud\.log\.(\d+).*)"); + const QRegularExpression rx(QRegularExpression::anchoredPattern(R"(.*owncloud\.log\.(\d+).*)")); int maxNumber = -1; foreach (const QString &s, files) { if (_logExpire > 0) { @@ -290,8 +291,9 @@ void Logger::enterNextLogFile() dir.remove(s); } } - if (s.startsWith(newLogName) && rx.exactMatch(s)) { - maxNumber = qMax(maxNumber, rx.cap(1).toInt()); + const auto rxMatch = rx.match(s); + if (s.startsWith(newLogName) && rxMatch.hasMatch()) { + maxNumber = qMax(maxNumber, rxMatch.captured(1).toInt()); } } newLogName.append("." + QString::number(maxNumber + 1)); diff --git a/src/libsync/networkjobs.cpp b/src/libsync/networkjobs.cpp index 5bd60f8d4..f2ba661e4 100644 --- a/src/libsync/networkjobs.cpp +++ b/src/libsync/networkjobs.cpp @@ -892,19 +892,21 @@ bool JsonApiJob::finished() QString jsonStr = QString::fromUtf8(reply()->readAll()); if (jsonStr.contains("")) { - QRegExp rex("(\\d+)"); - if (jsonStr.contains(rex)) { + const QRegularExpression rex("(\\d+)"); + const auto rexMatch = rex.match(jsonStr); + if (rexMatch.hasMatch()) { // this is a error message coming back from ocs. - statusCode = rex.cap(1).toInt(); + statusCode = rexMatch.captured(1).toInt(); } } else if(jsonStr.isEmpty() && httpStatusCode == notModifiedStatusCode){ qCWarning(lcJsonApiJob) << "Nothing changed so nothing to retrieve - status code: " << httpStatusCode; statusCode = httpStatusCode; } else { - QRegExp rex(R"("statuscode":(\d+))"); + const QRegularExpression rex(R"("statuscode":(\d+))"); // example: "{"ocs":{"meta":{"status":"ok","statuscode":100,"message":null},"data":{"version":{"major":8,"minor":"... (504) - if (jsonStr.contains(rex)) { - statusCode = rex.cap(1).toInt(); + const auto rxMatch = rex.match(jsonStr); + if (rxMatch.hasMatch()) { + statusCode = rxMatch.captured(1).toInt(); } } diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index e6b7383b9..10ccd97db 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -220,9 +220,10 @@ void GETFileJob::slotMetaDataChanged() qint64 start = 0; QByteArray ranges = reply()->rawHeader("Content-Range"); if (!ranges.isEmpty()) { - QRegExp rx("bytes (\\d+)-"); - if (rx.indexIn(ranges) >= 0) { - start = rx.cap(1).toLongLong(); + const QRegularExpression rx("bytes (\\d+)-"); + const auto rxMatch = rx.match(ranges); + if (rxMatch.hasMatch()) { + start = rxMatch.captured(1).toLongLong(); } } if (start != _resumeStart) { diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index 80a4c03cd..9813e63cb 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -579,7 +579,7 @@ void SyncEngine::startSync() invalidFilenamePattern = R"([\\:?*"<>|])"; } if (!invalidFilenamePattern.isEmpty()) - _discoveryPhase->_invalidFilenameRx = QRegExp(invalidFilenamePattern); + _discoveryPhase->_invalidFilenameRx = QRegularExpression(invalidFilenamePattern); _discoveryPhase->_serverBlacklistedFiles = _account->capabilities().blacklistedFiles(); _discoveryPhase->_ignoreHiddenFiles = ignoreHiddenFiles(); @@ -695,7 +695,7 @@ void SyncEngine::slotDiscoveryFinished() const QString script = qEnvironmentVariable("OWNCLOUD_POST_UPDATE_SCRIPT"); qCDebug(lcEngine) << "Post Update Script: " << script; - auto scriptArgs = script.split(QRegExp("\\s+"), Qt::SkipEmptyParts); + auto scriptArgs = script.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts); if (scriptArgs.size() > 0) { const auto scriptExecutable = scriptArgs.takeFirst(); QProcess::execute(scriptExecutable, scriptArgs); diff --git a/test/mockserver/httpserver.cpp b/test/mockserver/httpserver.cpp index fbc24e847..43a4c81ce 100644 --- a/test/mockserver/httpserver.cpp +++ b/test/mockserver/httpserver.cpp @@ -24,7 +24,7 @@ void HttpServer::readClient() { QTcpSocket* socket = (QTcpSocket*)sender(); if (socket->canReadLine()) { - QStringList tokens = QString(socket->readLine()).split(QRegExp("[ \r\n][ \r\n]*")); + QStringList tokens = QString(socket->readLine()).split(QRegularExpression("[ \r\n][ \r\n]*")); if (tokens[0] == "GET") { QTextStream os(socket); os.setAutoDetectUnicode(true); diff --git a/test/testutility.cpp b/test/testutility.cpp index f65bf985e..7fa16e573 100644 --- a/test/testutility.cpp +++ b/test/testutility.cpp @@ -123,8 +123,8 @@ private slots: qDebug() << "Version of installed Nextcloud: " << ver; QVERIFY(!ver.isEmpty()); - QRegExp rx(APPLICATION_SHORTNAME R"( version \d+\.\d+\.\d+.*)"); - QVERIFY(rx.exactMatch(ver)); + const QRegularExpression rx(QRegularExpression::anchoredPattern(APPLICATION_SHORTNAME R"( version \d+\.\d+\.\d+.*)")); + QVERIFY(rx.match(ver).hasMatch()); } else { QVERIFY(versionOfInstalledBinary().isEmpty()); }