diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-03-27 11:53:37 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-03-31 15:28:23 +0200 |
commit | 6a8132c8ee525426ffcdfdea80f8f53fd0bf10bb (patch) | |
tree | 9d0512e3f5ab95430ff1d60d5999b8a8ac5f670c /src | |
parent | d4a416df2ca6d3c6a227b6555cc7333bf8a09544 (diff) |
Get rid of QRegExp usage in QFtp
Change-Id: Ia8743467d5b4537fe324a1278b526eb16bf0f732
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/network/access/qftp.cpp | 27 | ||||
-rw-r--r-- | src/network/configure.cmake | 2 | ||||
-rw-r--r-- | src/network/configure.json | 2 |
3 files changed, 17 insertions, 14 deletions
diff --git a/src/network/access/qftp.cpp b/src/network/access/qftp.cpp index 2589c64b1c..e1b99c4599 100644 --- a/src/network/access/qftp.cpp +++ b/src/network/access/qftp.cpp @@ -47,7 +47,7 @@ #include "qtcpsocket.h" #include "qurlinfo_p.h" #include "qstringlist.h" -#include "qregexp.h" +#include "qregularexpression.h" #include "qtimer.h" #include "qfileinfo.h" #include "qtcpserver.h" @@ -621,18 +621,20 @@ bool QFtpDTP::parseDir(const QByteArray &buffer, const QString &userName, QUrlIn QString bufferStr = QString::fromUtf8(buffer).trimmed(); // Unix style FTP servers - QRegExp unixPattern(QLatin1String("^([\\-dl])([a-zA-Z\\-]{9,9})\\s+\\d+\\s+(\\S*)\\s+" - "(\\S*)\\s+(\\d+)\\s+(\\S+\\s+\\S+\\s+\\S+)\\s+(\\S.*)")); - if (unixPattern.indexIn(bufferStr) == 0) { - _q_parseUnixDir(unixPattern.capturedTexts(), userName, info); + QRegularExpression unixPattern(QLatin1String("^([\\-dl])([a-zA-Z\\-]{9,9})\\s+\\d+\\s+(\\S*)\\s+" + "(\\S*)\\s+(\\d+)\\s+(\\S+\\s+\\S+\\s+\\S+)\\s+(\\S.*)")); + auto unixPatternMatch = unixPattern.match(bufferStr); + if (unixPatternMatch.hasMatch()) { + _q_parseUnixDir(unixPatternMatch.capturedTexts(), userName, info); return true; } // DOS style FTP servers - QRegExp dosPattern(QLatin1String("^(\\d\\d-\\d\\d-\\d\\d\\ \\ \\d\\d:\\d\\d[AP]M)\\s+" - "(<DIR>|\\d+)\\s+(\\S.*)$")); - if (dosPattern.indexIn(bufferStr) == 0) { - _q_parseDosDir(dosPattern.capturedTexts(), userName, info); + QRegularExpression dosPattern(QLatin1String("^(\\d\\d-\\d\\d-\\d\\d\\ \\ \\d\\d:\\d\\d[AP]M)\\s+" + "(<DIR>|\\d+)\\s+(\\S.*)$")); + auto dosPatternMatch = dosPattern.match(bufferStr); + if (dosPatternMatch.hasMatch()) { + _q_parseDosDir(dosPatternMatch.capturedTexts(), userName, info); return true; } @@ -1064,14 +1066,15 @@ bool QFtpPI::processReply() // both examples where the parenthesis are used, and where // they are missing. We need to scan for the address and host // info. - QRegExp addrPortPattern(QLatin1String("(\\d+),(\\d+),(\\d+),(\\d+),(\\d+),(\\d+)")); - if (addrPortPattern.indexIn(replyText) == -1) { + QRegularExpression addrPortPattern(QLatin1String("(\\d+),(\\d+),(\\d+),(\\d+),(\\d+),(\\d+)")); + auto addrPortMatch = addrPortPattern.match(replyText); + if (!addrPortMatch.hasMatch()) { #if defined(QFTPPI_DEBUG) qDebug("QFtp: bad 227 response -- address and port information missing"); #endif // this error should be reported } else { - const QStringList lst = addrPortPattern.capturedTexts(); + const QStringList lst = addrPortMatch.capturedTexts(); QString host = lst[1] + QLatin1Char('.') + lst[2] + QLatin1Char('.') + lst[3] + QLatin1Char('.') + lst[4]; quint16 port = (lst[5].toUInt() << 8) + lst[6].toUInt(); waitForDtpToConnect = true; diff --git a/src/network/configure.cmake b/src/network/configure.cmake index e4699b7213..d9b47045ae 100644 --- a/src/network/configure.cmake +++ b/src/network/configure.cmake @@ -323,7 +323,7 @@ qt_feature("ftp" PUBLIC LABEL "FTP" PURPOSE "Provides support for the File Transfer Protocol in QNetworkAccessManager." AUTODETECT OFF - CONDITION QT_FEATURE_textdate + CONDITION QT_FEATURE_textdate AND QT_FEATURE_regularexpression ) qt_feature_definition("ftp" "QT_NO_FTP" NEGATE VALUE "1") qt_feature("http" PUBLIC diff --git a/src/network/configure.json b/src/network/configure.json index d6be41128a..84ad6cc4e8 100644 --- a/src/network/configure.json +++ b/src/network/configure.json @@ -344,7 +344,7 @@ "purpose": "Provides support for the File Transfer Protocol in QNetworkAccessManager.", "section": "Networking", "autoDetect": false, - "condition": "features.textdate", + "condition": "features.textdate && features.regularexpression", "output": [ "publicFeature", "feature" ] }, "http": { |