summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-05-25 13:12:51 +0200
committerLars Knoll <lars.knoll@qt.io>2020-06-10 09:09:36 +0200
commit122d66f69fa44e11202fccdab076fe1ec368f971 (patch)
tree07d6c3bca6a3be5f246fef74c9efd61e2fe18d8e
parent4ab3089a2cbcc3b0656a36e9c22ca2d72e150c7e (diff)
Port QtNetwork from QStringRef to QStringView
Task-number: QTBUG-84319 Change-Id: I0f4e83c282b58ab4cc5e397b21981978f79d92cf Reviewed-by: Alex Blasche <alexander.blasche@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
-rw-r--r--src/network/access/qftp.cpp20
-rw-r--r--src/network/access/qhsts.cpp2
-rw-r--r--src/network/access/qhsts_p.h8
-rw-r--r--src/network/access/qnetworkcookiejar.cpp2
-rw-r--r--src/network/kernel/qhostaddress.cpp8
-rw-r--r--src/network/kernel/qnetworkproxy_win.cpp10
-rw-r--r--src/network/ssl/qsslsocket.cpp6
-rw-r--r--src/network/ssl/qsslsocket_mac.cpp2
-rw-r--r--src/network/ssl/qsslsocket_openssl.cpp2
-rw-r--r--src/network/ssl/qsslsocket_openssl_symbols.cpp8
10 files changed, 34 insertions, 34 deletions
diff --git a/src/network/access/qftp.cpp b/src/network/access/qftp.cpp
index 048c272780..ffe0ae7b6b 100644
--- a/src/network/access/qftp.cpp
+++ b/src/network/access/qftp.cpp
@@ -580,10 +580,10 @@ static void _q_parseDosDir(const QStringList &tokens, const QString &userName, Q
int permissions = QUrlInfo::ReadOwner | QUrlInfo::WriteOwner
| QUrlInfo::ReadGroup | QUrlInfo::WriteGroup
| QUrlInfo::ReadOther | QUrlInfo::WriteOther;
- QStringRef ext;
+ QStringView ext;
int extIndex = name.lastIndexOf(QLatin1Char('.'));
if (extIndex != -1)
- ext = name.midRef(extIndex + 1);
+ ext = QStringView{name}.mid(extIndex + 1);
if (ext == QLatin1String("exe") || ext == QLatin1String("bat") || ext == QLatin1String("com"))
permissions |= QUrlInfo::ExeOwner | QUrlInfo::ExeGroup | QUrlInfo::ExeOther;
info->setPermissions(permissions);
@@ -949,19 +949,19 @@ void QFtpPI::readyRead()
QString endOfMultiLine(QLatin1String(count, 4));
QString lineCont(endOfMultiLine);
lineCont[3] = QLatin1Char('-');
- QStringRef lineLeft4 = line.leftRef(4);
+ QStringView lineLeft4 = QStringView{line}.left(4);
while (lineLeft4 != endOfMultiLine) {
if (lineLeft4 == lineCont)
- replyText += line.midRef(4); // strip 'xyz-'
+ replyText += QStringView{line}.mid(4); // strip 'xyz-'
else
replyText += line;
if (!commandSocket.canReadLine())
return;
line = QString::fromUtf8(commandSocket.readLine());
- lineLeft4 = line.leftRef(4);
+ lineLeft4 = QStringView{line}.left(4);
}
- replyText += line.midRef(4); // strip reply code 'xyz '
+ replyText += QStringView{line}.mid(4); // strip reply code 'xyz '
if (replyText.endsWith(QLatin1String("\r\n")))
replyText.chop(2);
@@ -1078,7 +1078,7 @@ bool QFtpPI::processReply()
} else {
++portPos;
QChar delimiter = replyText.at(portPos);
- const auto epsvParameters = replyText.midRef(portPos).split(delimiter);
+ const auto epsvParameters = QStringView{replyText}.mid(portPos).split(delimiter);
waitForDtpToConnect = true;
dtp.connectToHost(commandSocket.peerAddress().toString(),
@@ -1207,7 +1207,7 @@ bool QFtpPI::startNextCmd()
pendingCommands.pop_front();
#if defined(QFTPPI_DEBUG)
- qDebug("QFtpPI send: %s", currentCmd.leftRef(currentCmd.length() - 2).toLatin1().constData());
+ qDebug("QFtpPI send: %s", QStringView{currentCmd}.left(currentCmd.length() - 2).toLatin1().constData());
#endif
state = Waiting;
commandSocket.write(currentCmd.toUtf8());
@@ -2031,7 +2031,7 @@ int QFtp::rename(const QString &oldname, const QString &newname)
*/
int QFtp::rawCommand(const QString &command)
{
- const QString cmd = QStringRef(&command).trimmed() + QLatin1String("\r\n");
+ const QString cmd = QStringView{command}.trimmed() + QLatin1String("\r\n");
return d_func()->addCommand(new QFtpCommand(RawCommand, QStringList(cmd)));
}
@@ -2262,7 +2262,7 @@ void QFtpPrivate::_q_startNextCommand()
// through.
if (c->command == QFtp::Login && !proxyHost.isEmpty()) {
QString loginString;
- loginString += QStringRef(&c->rawCmds.constFirst()).trimmed() + QLatin1Char('@') + host;
+ loginString += QStringView{c->rawCmds.constFirst()}.trimmed() + QLatin1Char('@') + host;
if (port && port != 21)
loginString += QLatin1Char(':') + QString::number(port);
loginString += QLatin1String("\r\n");
diff --git a/src/network/access/qhsts.cpp b/src/network/access/qhsts.cpp
index 0cef0ad3dc..e473008305 100644
--- a/src/network/access/qhsts.cpp
+++ b/src/network/access/qhsts.cpp
@@ -194,7 +194,7 @@ bool QHstsCache::isKnownHost(const QUrl &url) const
bool superDomainMatch = false;
const QString hostNameAsString(url.host());
- HostName nameToTest(static_cast<QStringRef>(&hostNameAsString));
+ HostName nameToTest(QStringView{hostNameAsString});
while (nameToTest.fragment.size()) {
auto const pos = knownHosts.find(nameToTest);
if (pos != knownHosts.end()) {
diff --git a/src/network/access/qhsts_p.h b/src/network/access/qhsts_p.h
index b5be4ff455..8ebf7294dd 100644
--- a/src/network/access/qhsts_p.h
+++ b/src/network/access/qhsts_p.h
@@ -94,18 +94,18 @@ private:
struct HostName
{
explicit HostName(const QString &n) : name(n) { }
- explicit HostName(const QStringRef &r) : fragment(r) { }
+ explicit HostName(QStringView r) : fragment(r) { }
bool operator < (const HostName &rhs) const
{
if (fragment.size()) {
if (rhs.fragment.size())
return fragment < rhs.fragment;
- return fragment < QStringRef(&rhs.name);
+ return fragment < QStringView{rhs.name};
}
if (rhs.fragment.size())
- return QStringRef(&name) < rhs.fragment;
+ return QStringView{name} < rhs.fragment;
return name < rhs.name;
}
@@ -114,7 +114,7 @@ private:
// name, removing subdomain names (such HostName object is 'transient', it
// must not outlive the original QString object.
QString name;
- QStringRef fragment;
+ QStringView fragment;
};
mutable std::map<HostName, QHstsPolicy> knownHosts;
diff --git a/src/network/access/qnetworkcookiejar.cpp b/src/network/access/qnetworkcookiejar.cpp
index 62225b28d1..c01bd339ca 100644
--- a/src/network/access/qnetworkcookiejar.cpp
+++ b/src/network/access/qnetworkcookiejar.cpp
@@ -170,7 +170,7 @@ static inline bool isParentDomain(const QString &domain, const QString &referenc
if (!reference.startsWith(QLatin1Char('.')))
return domain == reference;
- return domain.endsWith(reference) || domain == reference.midRef(1);
+ return domain.endsWith(reference) || domain == QStringView{reference}.mid(1);
}
/*!
diff --git a/src/network/kernel/qhostaddress.cpp b/src/network/kernel/qhostaddress.cpp
index 0783c0751f..c318766796 100644
--- a/src/network/kernel/qhostaddress.cpp
+++ b/src/network/kernel/qhostaddress.cpp
@@ -136,7 +136,7 @@ void QHostAddressPrivate::setAddress(const Q_IPV6ADDR &a_)
static bool parseIp6(const QString &address, QIPAddressUtils::IPv6Address &addr, QString *scopeId)
{
- QStringRef tmp(&address);
+ QStringView tmp(address);
int scopeIdPos = tmp.lastIndexOf(QLatin1Char('%'));
if (scopeIdPos != -1) {
*scopeId = tmp.mid(scopeIdPos + 1).toString();
@@ -144,7 +144,7 @@ static bool parseIp6(const QString &address, QIPAddressUtils::IPv6Address &addr,
} else {
scopeId->clear();
}
- return QIPAddressUtils::parseIp6(addr, tmp.constBegin(), tmp.constEnd()) == nullptr;
+ return QIPAddressUtils::parseIp6(addr, tmp.begin(), tmp.end()) == nullptr;
}
bool QHostAddressPrivate::parse(const QString &ipString)
@@ -1103,7 +1103,7 @@ QPair<QHostAddress, int> QHostAddress::parseSubnet(const QString &subnet)
return invalid;
int slash = subnet.indexOf(QLatin1Char('/'));
- QStringRef netStr(&subnet);
+ QStringView netStr(subnet);
if (slash != -1)
netStr.truncate(slash);
@@ -1123,7 +1123,7 @@ QPair<QHostAddress, int> QHostAddress::parseSubnet(const QString &subnet)
netmask = parser.prefixLength();
} else {
bool ok;
- netmask = subnet.midRef(slash + 1).toUInt(&ok);
+ netmask = QStringView{subnet}.mid(slash + 1).toUInt(&ok);
if (!ok)
return invalid; // failed to parse the subnet
}
diff --git a/src/network/kernel/qnetworkproxy_win.cpp b/src/network/kernel/qnetworkproxy_win.cpp
index c4dc33f66f..713db7d5b9 100644
--- a/src/network/kernel/qnetworkproxy_win.cpp
+++ b/src/network/kernel/qnetworkproxy_win.cpp
@@ -298,15 +298,15 @@ static QList<QNetworkProxy> parseServerList(const QNetworkProxyQuery &query, con
quint16 port = 8080;
int pos = entry.indexOf(QLatin1Char('='));
- QStringRef scheme;
- QStringRef protocolTag;
+ QStringView scheme;
+ QStringView protocolTag;
if (pos != -1) {
- scheme = protocolTag = entry.leftRef(pos);
+ scheme = protocolTag = QStringView{entry}.left(pos);
server = pos + 1;
}
pos = entry.indexOf(QLatin1String("://"), server);
if (pos != -1) {
- scheme = entry.midRef(server, pos - server);
+ scheme = QStringView{entry}.mid(server, pos - server);
server = pos + 3;
}
@@ -329,7 +329,7 @@ static QList<QNetworkProxy> parseServerList(const QNetworkProxyQuery &query, con
pos = entry.indexOf(QLatin1Char(':'), server);
if (pos != -1) {
bool ok;
- uint value = entry.midRef(pos + 1).toUInt(&ok);
+ uint value = QStringView{entry}.mid(pos + 1).toUInt(&ok);
if (!ok || value > 65535)
continue; // invalid port number
diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp
index 64e556ac3c..e4627eba68 100644
--- a/src/network/ssl/qsslsocket.cpp
+++ b/src/network/ssl/qsslsocket.cpp
@@ -3083,13 +3083,13 @@ bool QSslSocketPrivate::isMatchingHostname(const QString &cn, const QString &hos
return false;
// Check characters preceding * (if any) match
- if (wildcard && hostname.leftRef(wildcard).compare(cn.leftRef(wildcard), Qt::CaseInsensitive) != 0)
+ if (wildcard && QStringView{hostname}.left(wildcard).compare(QStringView{cn}.left(wildcard), Qt::CaseInsensitive) != 0)
return false;
// Check characters following first . match
int hnDot = hostname.indexOf(QLatin1Char('.'));
- if (hostname.midRef(hnDot + 1) != cn.midRef(firstCnDot + 1)
- && hostname.midRef(hnDot + 1) != QLatin1String(QUrl::toAce(cn.mid(firstCnDot + 1)))) {
+ if (QStringView{hostname}.mid(hnDot + 1) != QStringView{cn}.mid(firstCnDot + 1)
+ && QStringView{hostname}.mid(hnDot + 1) != QLatin1String(QUrl::toAce(cn.mid(firstCnDot + 1)))) {
return false;
}
diff --git a/src/network/ssl/qsslsocket_mac.cpp b/src/network/ssl/qsslsocket_mac.cpp
index 1ae32b0330..cc822c182c 100644
--- a/src/network/ssl/qsslsocket_mac.cpp
+++ b/src/network/ssl/qsslsocket_mac.cpp
@@ -804,7 +804,7 @@ QSslCipher QSslSocketBackendPrivate::QSslCipher_from_SSLCipherSuite(SSLCipherSui
ciph.d->protocol = QSsl::TlsV1_2;
ciph.d->protocolString = QLatin1String("TLSv1.2");
- const auto bits = ciph.d->name.splitRef(QLatin1Char('-'));
+ const auto bits = QStringView{ciph.d->name}.split(QLatin1Char('-'));
if (bits.size() >= 2) {
if (bits.size() == 2 || bits.size() == 3) {
ciph.d->keyExchangeMethod = QLatin1String("RSA");
diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp
index 9d95a58118..ea59063e72 100644
--- a/src/network/ssl/qsslsocket_openssl.cpp
+++ b/src/network/ssl/qsslsocket_openssl.cpp
@@ -424,7 +424,7 @@ QSslCipher QSslSocketBackendPrivate::QSslCipher_from_SSL_CIPHER(const SSL_CIPHER
char buf [256];
QString descriptionOneLine = QString::fromLatin1(q_SSL_CIPHER_description(cipher, buf, sizeof(buf)));
- const auto descriptionList = descriptionOneLine.splitRef(QLatin1Char(' '), Qt::SkipEmptyParts);
+ const auto descriptionList = QStringView{descriptionOneLine}.split(QLatin1Char(' '), Qt::SkipEmptyParts);
if (descriptionList.size() > 5) {
// ### crude code.
ciph.d->isNull = false;
diff --git a/src/network/ssl/qsslsocket_openssl_symbols.cpp b/src/network/ssl/qsslsocket_openssl_symbols.cpp
index 1756333371..c74a65ab37 100644
--- a/src/network/ssl/qsslsocket_openssl_symbols.cpp
+++ b/src/network/ssl/qsslsocket_openssl_symbols.cpp
@@ -532,7 +532,7 @@ bool q_resolveOpenSslSymbols()
struct NumericallyLess
{
typedef bool result_type;
- result_type operator()(const QStringRef &lhs, const QStringRef &rhs) const
+ result_type operator()(QStringView lhs, QStringView rhs) const
{
bool ok = false;
int b = 0;
@@ -552,10 +552,10 @@ struct NumericallyLess
struct LibGreaterThan
{
typedef bool result_type;
- result_type operator()(const QString &lhs, const QString &rhs) const
+ result_type operator()(QStringView lhs, QStringView rhs) const
{
- const QVector<QStringRef> lhsparts = lhs.splitRef(QLatin1Char('.'));
- const QVector<QStringRef> rhsparts = rhs.splitRef(QLatin1Char('.'));
+ const QVector<QStringView> lhsparts = lhs.split(QLatin1Char('.'));
+ const QVector<QStringView> rhsparts = rhs.split(QLatin1Char('.'));
Q_ASSERT(lhsparts.count() > 1 && rhsparts.count() > 1);
// note: checking rhs < lhs, the same as lhs > rhs