Bladeren bron

Replace deprecated QRegExp with QRegularExpression.

Signed-off-by: alex-z <blackslayer4@gmail.com>
alex-z 4 jaren geleden
bovenliggende
commit
c52718c104

+ 1 - 1
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('/'))) {

+ 4 - 3
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", "<html><head><title>404 Not Found</title></head><body><center><h1>404 Not Found</h1></center></body></html>");
                     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;

+ 4 - 3
src/gui/notificationconfirmjob.cpp

@@ -56,10 +56,11 @@ bool NotificationConfirmJob::finished()
     const QString replyStr = reply()->readAll();
 
     if (replyStr.contains("<?xml version=\"1.0\"?>")) {
-        QRegExp rex("<statuscode>(\\d+)</statuscode>");
-        if (replyStr.contains(rex)) {
+        const QRegularExpression rex("<statuscode>(\\d+)</statuscode>");
+        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);

+ 2 - 2
src/gui/sharedialog.cpp

@@ -96,8 +96,8 @@ ShareDialog::ShareDialog(QPointer<AccountState> 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.

+ 5 - 4
src/gui/syncrunfilelog.cpp

@@ -12,7 +12,7 @@
  * for more details.
  */
 
-#include <QRegExp>
+#include <QRegularExpression>
 
 #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);
         }
     }
 

+ 0 - 1
src/libsync/creds/credentialscommon.cpp

@@ -14,7 +14,6 @@
  */
 
 #include <QList>
-#include <QRegExp>
 #include <QString>
 #include <QSslCertificate>
 #include <QSslConfiguration>

+ 1 - 1
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;

+ 1 - 1
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<bool(const QString &)> _shouldDiscoverLocaly;

+ 5 - 3
src/libsync/logger.cpp

@@ -17,6 +17,7 @@
 #include "config.h"
 
 #include <QDir>
+#include <QRegularExpression>
 #include <QStringList>
 #include <QtGlobal>
 #include <QTextCodec>
@@ -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));

+ 8 - 6
src/libsync/networkjobs.cpp

@@ -892,19 +892,21 @@ bool JsonApiJob::finished()
 
     QString jsonStr = QString::fromUtf8(reply()->readAll());
     if (jsonStr.contains("<?xml version=\"1.0\"?>")) {
-        QRegExp rex("<statuscode>(\\d+)</statuscode>");
-        if (jsonStr.contains(rex)) {
+        const QRegularExpression rex("<statuscode>(\\d+)</statuscode>");
+        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();
         }
     }
 

+ 4 - 3
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) {

+ 2 - 2
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);

+ 1 - 1
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);

+ 2 - 2
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());
         }