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>
This commit is contained in:
parent
4ab3089a2c
commit
122d66f69f
@ -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");
|
||||
|
@ -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()) {
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user