From 301f0a6fb025968ee73c74b8dffea1e7fe6f67e0 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Tue, 12 Apr 2022 15:12:22 +0200 Subject: [PATCH] QtNetwork: replace remaining uses of QLatin1String by QLatin1StringView MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-98434 Change-Id: I0bb9d534ee42ccbf7d353e251ef58901a86923b4 Reviewed-by: Qt CI Bot Reviewed-by: MÃ¥rten Nordheim --- src/network/access/qhttp2protocolhandler.cpp | 10 +++++----- src/network/access/qhttpthreaddelegate.cpp | 8 ++++---- src/network/access/qnetworkdiskcache.cpp | 2 +- src/network/access/qnetworkreplyhttpimpl.cpp | 2 +- src/network/kernel/qhostinfo_p.h | 2 +- src/network/kernel/qnetworkinterface_unix.cpp | 4 ++-- src/network/kernel/qnetworkproxy_generic.cpp | 2 +- src/network/socket/qabstractsocketengine.cpp | 2 +- src/network/socket/qsocks5socketengine.cpp | 2 +- src/network/ssl/qsslsocket.cpp | 4 ++-- src/plugins/tls/openssl/qdtls_openssl.cpp | 2 +- src/plugins/tls/openssl/qsslsocket_openssl_symbols.cpp | 4 ++-- src/plugins/tls/openssl/qtls_openssl.cpp | 2 +- src/plugins/tls/openssl/qtlsbackend_openssl.cpp | 4 ++-- src/plugins/tls/securetransport/qtls_st.cpp | 2 +- 15 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/network/access/qhttp2protocolhandler.cpp b/src/network/access/qhttp2protocolhandler.cpp index 7c6d09d41c..7af0bd0875 100644 --- a/src/network/access/qhttp2protocolhandler.cpp +++ b/src/network/access/qhttp2protocolhandler.cpp @@ -151,7 +151,7 @@ QUrl urlkey_from_request(const QHttpNetworkRequest &request) url.setScheme(request.url().scheme()); url.setAuthority(request.url().authority(QUrl::FullyEncoded | QUrl::RemoveUserInfo)); - url.setPath(QLatin1String(request.uri(false))); + url.setPath(QLatin1StringView(request.uri(false))); return url; } @@ -1537,9 +1537,9 @@ bool QHttp2ProtocolHandler::tryReserveStream(const Http2::Frame &pushPromiseFram return false; QUrl url; - url.setScheme(QLatin1String(pseudoHeaders[":scheme"])); - url.setAuthority(QLatin1String(pseudoHeaders[":authority"])); - url.setPath(QLatin1String(pseudoHeaders[":path"])); + url.setScheme(QLatin1StringView(pseudoHeaders[":scheme"])); + url.setAuthority(QLatin1StringView(pseudoHeaders[":authority"])); + url.setPath(QLatin1StringView(pseudoHeaders[":path"])); if (!url.isValid()) return false; @@ -1636,7 +1636,7 @@ void QHttp2ProtocolHandler::connectionError(Http2::Http2Error errorCode, m_channel->emitFinishedWithError(error, message); for (auto &stream: activeStreams) - finishStreamWithError(stream, error, QLatin1String(message)); + finishStreamWithError(stream, error, QLatin1StringView(message)); closeSession(); } diff --git a/src/network/access/qhttpthreaddelegate.cpp b/src/network/access/qhttpthreaddelegate.cpp index 94fa6e428c..d7ec10c696 100644 --- a/src/network/access/qhttpthreaddelegate.cpp +++ b/src/network/access/qhttpthreaddelegate.cpp @@ -522,8 +522,8 @@ void QHttpThreadDelegate::finishedSlot() if (httpReply->statusCode() >= 400) { // it's an error reply - QString msg = QLatin1String(QT_TRANSLATE_NOOP("QNetworkReply", - "Error transferring %1 - server replied: %2")); + QString msg = QLatin1StringView(QT_TRANSLATE_NOOP("QNetworkReply", + "Error transferring %1 - server replied: %2")); msg = msg.arg(httpRequest.url().toString(), httpReply->reasonPhrase()); emit error(statusCodeFromHttp(httpReply->statusCode(), httpRequest.url()), msg); } @@ -548,8 +548,8 @@ void QHttpThreadDelegate::synchronousFinishedSlot() #endif if (httpReply->statusCode() >= 400) { // it's an error reply - QString msg = QLatin1String(QT_TRANSLATE_NOOP("QNetworkReply", - "Error transferring %1 - server replied: %2")); + QString msg = QLatin1StringView(QT_TRANSLATE_NOOP("QNetworkReply", + "Error transferring %1 - server replied: %2")); incomingErrorDetail = msg.arg(httpRequest.url().toString(), httpReply->reasonPhrase()); incomingErrorCode = statusCodeFromHttp(httpReply->statusCode(), httpRequest.url()); } diff --git a/src/network/access/qnetworkdiskcache.cpp b/src/network/access/qnetworkdiskcache.cpp index 78bd4f4e7e..069267e543 100644 --- a/src/network/access/qnetworkdiskcache.cpp +++ b/src/network/access/qnetworkdiskcache.cpp @@ -600,7 +600,7 @@ QString QNetworkDiskCachePrivate::uniqueFileName(const QUrl &url) const QByteArray id = QByteArray::number(*(qlonglong*)hash.data(), 36).left(8); // generates /<8-char filname.d> uint code = (uint)id.at(id.length()-1) % 16; - QString pathFragment = QString::number(code, 16) + u'/' + QLatin1String(id) + CACHE_POSTFIX; + QString pathFragment = QString::number(code, 16) + u'/' + QLatin1StringView(id) + CACHE_POSTFIX; return pathFragment; } diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 3612fe301d..0a47bc9f71 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -1316,7 +1316,7 @@ void QNetworkReplyHttpImplPrivate::checkForRedirect(const int statusCode) QByteArray header = q->rawHeader("location"); QUrl url = QUrl(QString::fromUtf8(header)); if (!url.isValid()) - url = QUrl(QLatin1String(header)); + url = QUrl(QLatin1StringView(header)); q->setAttribute(QNetworkRequest::RedirectionTargetAttribute, url); } } diff --git a/src/network/kernel/qhostinfo_p.h b/src/network/kernel/qhostinfo_p.h index b10b765148..f47c1ab57d 100644 --- a/src/network/kernel/qhostinfo_p.h +++ b/src/network/kernel/qhostinfo_p.h @@ -127,7 +127,7 @@ class QHostInfoPrivate public: inline QHostInfoPrivate() : err(QHostInfo::NoError), - errorStr(QLatin1String(QT_TRANSLATE_NOOP("QHostInfo", "Unknown error"))), + errorStr(QLatin1StringView(QT_TRANSLATE_NOOP("QHostInfo", "Unknown error"))), lookupId(0) { } diff --git a/src/network/kernel/qnetworkinterface_unix.cpp b/src/network/kernel/qnetworkinterface_unix.cpp index 94f3a53c09..cb4e1f7048 100644 --- a/src/network/kernel/qnetworkinterface_unix.cpp +++ b/src/network/kernel/qnetworkinterface_unix.cpp @@ -247,7 +247,7 @@ static QNetworkInterfacePrivate *findInterface(int socket, QList::Iterator if_it = interfaces.begin(); for ( ; if_it != interfaces.end(); ++if_it) - if ((*if_it)->name == QLatin1String(req.ifr_name)) { + if ((*if_it)->name == QLatin1StringView(req.ifr_name)) { // existing interface iface = *if_it; break; @@ -627,7 +627,7 @@ static QList interfaceListing() interfaces = createInterfaces(interfaceListing); for (ifaddrs *ptr = interfaceListing; ptr; ptr = ptr->ifa_next) { // Find the interface - QLatin1String name(ptr->ifa_name); + QLatin1StringView name(ptr->ifa_name); QNetworkInterfacePrivate *iface = nullptr; QList::Iterator if_it = interfaces.begin(); for ( ; if_it != interfaces.end(); ++if_it) diff --git a/src/network/kernel/qnetworkproxy_generic.cpp b/src/network/kernel/qnetworkproxy_generic.cpp index 87b3e4d653..64284cb85f 100644 --- a/src/network/kernel/qnetworkproxy_generic.cpp +++ b/src/network/kernel/qnetworkproxy_generic.cpp @@ -64,7 +64,7 @@ static bool ignoreProxyFor(const QNetworkProxyQuery &query) const QList noProxyTokens = noProxy.split(','); for (const QByteArray &rawToken : noProxyTokens) { - auto token = QLatin1String(rawToken).trimmed(); + auto token = QLatin1StringView(rawToken).trimmed(); // Since we use suffix matching, "*" is our 'default' behaviour if (token.startsWith(u'*')) diff --git a/src/network/socket/qabstractsocketengine.cpp b/src/network/socket/qabstractsocketengine.cpp index 50462fb11f..16d39e043c 100644 --- a/src/network/socket/qabstractsocketengine.cpp +++ b/src/network/socket/qabstractsocketengine.cpp @@ -73,7 +73,7 @@ QSocketEngineHandler::~QSocketEngineHandler() QAbstractSocketEnginePrivate::QAbstractSocketEnginePrivate() : socketError(QAbstractSocket::UnknownSocketError) , hasSetSocketError(false) - , socketErrorString(QLatin1String(QT_TRANSLATE_NOOP(QSocketLayer, "Unknown error"))) + , socketErrorString(QLatin1StringView(QT_TRANSLATE_NOOP(QSocketLayer, "Unknown error"))) , socketState(QAbstractSocket::UnconnectedState) , socketType(QAbstractSocket::UnknownSocketType) , socketProtocol(QAbstractSocket::UnknownNetworkLayerProtocol) diff --git a/src/network/socket/qsocks5socketengine.cpp b/src/network/socket/qsocks5socketengine.cpp index 3625041efb..05efc3cbe6 100644 --- a/src/network/socket/qsocks5socketengine.cpp +++ b/src/network/socket/qsocks5socketengine.cpp @@ -1387,7 +1387,7 @@ bool QSocks5SocketEngine::bind(const QHostAddress &addr, quint16 port) // binding timed out setError(QAbstractSocket::SocketTimeoutError, - QLatin1String(QT_TRANSLATE_NOOP("QSocks5SocketEngine", "Network operation timed out"))); + QLatin1StringView(QT_TRANSLATE_NOOP("QSocks5SocketEngine", "Network operation timed out"))); ///### delete d->udpSocket; ///### d->udpSocket = 0; diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp index 9401f4a773..085ed2c18a 100644 --- a/src/network/ssl/qsslsocket.cpp +++ b/src/network/ssl/qsslsocket.cpp @@ -3061,7 +3061,7 @@ bool QSslSocketPrivate::isMatchingHostname(const QString &cn, const QString &hos // Check this is a wildcard cert, if not then just compare the strings if (wildcard < 0) - return QLatin1String(QUrl::toAce(cn)) == hostname; + return QLatin1StringView(QUrl::toAce(cn)) == hostname; qsizetype firstCnDot = cn.indexOf(u'.'); qsizetype secondCnDot = cn.indexOf(u'.', firstCnDot+1); @@ -3090,7 +3090,7 @@ bool QSslSocketPrivate::isMatchingHostname(const QString &cn, const QString &hos // Check characters following first . match qsizetype hnDot = hostname.indexOf(u'.'); if (QStringView{hostname}.mid(hnDot + 1) != QStringView{cn}.mid(firstCnDot + 1) - && QStringView{hostname}.mid(hnDot + 1) != QLatin1String(QUrl::toAce(cn.mid(firstCnDot + 1)))) { + && QStringView{hostname}.mid(hnDot + 1) != QLatin1StringView(QUrl::toAce(cn.mid(firstCnDot + 1)))) { return false; } diff --git a/src/plugins/tls/openssl/qdtls_openssl.cpp b/src/plugins/tls/openssl/qdtls_openssl.cpp index a1f2c707f9..7a2c29d7a4 100644 --- a/src/plugins/tls/openssl/qdtls_openssl.cpp +++ b/src/plugins/tls/openssl/qdtls_openssl.cpp @@ -653,7 +653,7 @@ bool DtlsState::initTls(QDtlsBasePrivate *dtlsBase) static QString msgFunctionFailed(const char *function) { //: %1: Some function - return QDtls::tr("%1 failed").arg(QLatin1String(function)); + return QDtls::tr("%1 failed").arg(QLatin1StringView(function)); } bool DtlsState::initCtxAndConnection(QDtlsBasePrivate *dtlsBase) diff --git a/src/plugins/tls/openssl/qsslsocket_openssl_symbols.cpp b/src/plugins/tls/openssl/qsslsocket_openssl_symbols.cpp index 30797e5a29..7bcd205b3a 100644 --- a/src/plugins/tls/openssl/qsslsocket_openssl_symbols.cpp +++ b/src/plugins/tls/openssl/qsslsocket_openssl_symbols.cpp @@ -647,7 +647,7 @@ static QStringList libraryPathList() } Q_NEVER_INLINE -static QStringList findAllLibs(QLatin1String filter) +static QStringList findAllLibs(QLatin1StringView filter) { const QStringList paths = libraryPathList(); QStringList found; @@ -682,7 +682,7 @@ struct LoadedOpenSsl { std::unique_ptr ssl, crypto; }; -static bool tryToLoadOpenSslWin32Library(QLatin1String ssleay32LibName, QLatin1String libeay32LibName, LoadedOpenSsl &result) +static bool tryToLoadOpenSslWin32Library(QLatin1StringView ssleay32LibName, QLatin1StringView libeay32LibName, LoadedOpenSsl &result) { auto ssleay32 = std::make_unique(ssleay32LibName); if (!ssleay32->load(false)) { diff --git a/src/plugins/tls/openssl/qtls_openssl.cpp b/src/plugins/tls/openssl/qtls_openssl.cpp index f022ebcd6d..d95756e2d2 100644 --- a/src/plugins/tls/openssl/qtls_openssl.cpp +++ b/src/plugins/tls/openssl/qtls_openssl.cpp @@ -85,7 +85,7 @@ QSsl::AlertLevel tlsAlertLevel(int value) QString tlsAlertDescription(int value) { - QString description = QLatin1String(q_SSL_alert_desc_string_long(value)); + QString description = QLatin1StringView(q_SSL_alert_desc_string_long(value)); if (!description.size()) description = "no description provided"_L1; return description; diff --git a/src/plugins/tls/openssl/qtlsbackend_openssl.cpp b/src/plugins/tls/openssl/qtlsbackend_openssl.cpp index 6693cc8142..61613dc0f9 100644 --- a/src/plugins/tls/openssl/qtlsbackend_openssl.cpp +++ b/src/plugins/tls/openssl/qtlsbackend_openssl.cpp @@ -230,7 +230,7 @@ void QTlsBackendOpenSSL::ensureCiphersAndCertsLoaded() const QStringList symLinkFilter; symLinkFilter << "[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].[0-9]"_L1; for (const auto &dir : dirs) { - QDirIterator iterator(QLatin1String(dir), symLinkFilter, QDir::Files); + QDirIterator iterator(QLatin1StringView(dir), symLinkFilter, QDir::Files); if (iterator.hasNext()) { QSslSocketPrivate::setRootCertOnDemandLoadingSupported(true); break; @@ -414,7 +414,7 @@ QList systemCaCertificates() QDir currentDir; currentDir.setNameFilters(QStringList{QStringLiteral("*.pem"), QStringLiteral("*.crt")}); for (const auto &directory : directories) { - currentDir.setPath(QLatin1String(directory)); + currentDir.setPath(QLatin1StringView(directory)); QDirIterator it(currentDir); while (it.hasNext()) { // use canonical path here to not load the same certificate twice if symlinked diff --git a/src/plugins/tls/securetransport/qtls_st.cpp b/src/plugins/tls/securetransport/qtls_st.cpp index 60127ca885..38beb0c6a4 100644 --- a/src/plugins/tls/securetransport/qtls_st.cpp +++ b/src/plugins/tls/securetransport/qtls_st.cpp @@ -119,7 +119,7 @@ EphemeralSecKeychain::EphemeralSecKeychain() Q_ASSERT(uuidAsByteArray.size() > 2); Q_ASSERT(uuidAsByteArray.startsWith('{')); Q_ASSERT(uuidAsByteArray.endsWith('}')); - const auto uuidAsString = QLatin1String(uuidAsByteArray.data(), uuidAsByteArray.size()).mid(1, uuidAsByteArray.size() - 2); + const auto uuidAsString = QLatin1StringView(uuidAsByteArray.data(), uuidAsByteArray.size()).mid(1, uuidAsByteArray.size() - 2); const QString keychainName = QDir::tempPath() + QDir::separator() + uuidAsString + ".keychain"_L1;