QtNetwork: stop using QLatin1Char constructor for creating char literals

Required for porting away from QLatin1Char/QLatin1String in scope of
QTBUG-98434.

As a drive-by, fix qsizetype -> int narrowing conversion warnings for
the touched lines.

Change-Id: I121f87214b77aeab1dfd3e62dc5adaa6255cc0e0
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Sona Kurazyan 2022-04-12 14:01:55 +02:00
parent e2a1329910
commit f2637e1a77
22 changed files with 63 additions and 66 deletions

View File

@ -210,7 +210,7 @@ bool QHstsCache::isKnownHost(const QUrl &url) const
}
}
const int dot = nameToTest.fragment.indexOf(QLatin1Char('.'));
const qsizetype dot = nameToTest.fragment.indexOf(u'.');
if (dot == -1)
break;

View File

@ -172,7 +172,7 @@ static QByteArray makeCacheKey(QUrl &url, QNetworkProxy *proxy, const QString &p
Q_UNUSED(proxy);
#endif
if (!peerVerifyName.isEmpty())
result += QLatin1Char(':') + peerVerifyName;
result += u':' + peerVerifyName;
return "http-connection:" + std::move(result).toLatin1();
}

View File

@ -131,7 +131,7 @@ void QNetworkAccessFileBackend::open()
QString fileName = url.toLocalFile();
if (fileName.isEmpty()) {
if (url.scheme() == QLatin1String("qrc")) {
fileName = QLatin1Char(':') + url.path();
fileName = u':' + url.path();
} else {
#if defined(Q_OS_ANDROID)
if (url.scheme() == QLatin1String("assets"))

View File

@ -541,7 +541,7 @@ QByteArray QNetworkCookie::toRawForm(RawForm form) const
}
if (!d->domain.isEmpty()) {
result += "; domain=";
if (d->domain.startsWith(QLatin1Char('.'))) {
if (d->domain.startsWith(u'.')) {
result += '.';
result += QUrl::toAce(d->domain.mid(1));
} else {
@ -1028,7 +1028,7 @@ QList<QNetworkCookie> QNetworkCookiePrivate::parseSetCookieHeaderLine(const QByt
if (!rawDomain.isEmpty()) {
QString maybeLeadingDot;
if (rawDomain.startsWith('.')) {
maybeLeadingDot = QLatin1Char('.');
maybeLeadingDot = u'.';
rawDomain = rawDomain.mid(1);
}
@ -1096,9 +1096,9 @@ void QNetworkCookie::normalize(const QUrl &url)
// don't do path checking. See QTBUG-5815
if (d->path.isEmpty()) {
QString pathAndFileName = url.path();
QString defaultPath = pathAndFileName.left(pathAndFileName.lastIndexOf(QLatin1Char('/'))+1);
QString defaultPath = pathAndFileName.left(pathAndFileName.lastIndexOf(u'/') + 1);
if (defaultPath.isEmpty())
defaultPath = QLatin1Char('/');
defaultPath = u'/';
d->path = defaultPath;
}
@ -1108,12 +1108,12 @@ void QNetworkCookie::normalize(const QUrl &url)
QHostAddress hostAddress(d->domain);
if (hostAddress.protocol() != QAbstractSocket::IPv4Protocol
&& hostAddress.protocol() != QAbstractSocket::IPv6Protocol
&& !d->domain.startsWith(QLatin1Char('.'))) {
&& !d->domain.startsWith(u'.')) {
// Ensure the domain starts with a dot if its field was not empty
// in the HTTP header. There are some servers that forget the
// leading dot and this is actually forbidden according to RFC 2109,
// but all browsers accept it anyway so we do that as well.
d->domain.prepend(QLatin1Char('.'));
d->domain.prepend(u'.');
}
}
}

View File

@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE
static bool qIsEffectiveTLD(QStringView domain)
{
// provide minimal checking by not accepting cookies on real TLDs
return !domain.contains(QLatin1Char('.'));
return !domain.contains(u'.');
}
QT_END_NAMESPACE
#endif
@ -167,7 +167,7 @@ static inline bool isParentPath(const QString &path, const QString &reference)
static inline bool isParentDomain(const QString &domain, const QString &reference)
{
if (!reference.startsWith(QLatin1Char('.')))
if (!reference.startsWith(u'.'))
return domain == reference;
return domain.endsWith(reference) || domain == QStringView{reference}.mid(1);
@ -250,13 +250,13 @@ QList<QNetworkCookie> QNetworkCookieJar::cookiesForUrl(const QUrl &url) const
continue;
QString domain = it->domain();
if (domain.startsWith(QLatin1Char('.'))) /// Qt6?: remove when compliant with RFC6265
if (domain.startsWith(u'.')) /// Qt6?: remove when compliant with RFC6265
domain = domain.mid(1);
#if QT_CONFIG(topleveldomain)
if (qIsEffectiveTLD(domain) && url.host() != domain)
continue;
#else
if (!domain.contains(QLatin1Char('.')) && url.host() != domain)
if (!domain.contains(u'.') && url.host() != domain)
continue;
#endif // topleveldomain
@ -356,7 +356,7 @@ bool QNetworkCookieJar::validateCookie(const QNetworkCookie &cookie, const QUrl
if (!isParentDomain(domain, host) && !isParentDomain(host, domain))
return false; // not accepted
if (domain.startsWith(QLatin1Char('.')))
if (domain.startsWith(u'.'))
domain = domain.mid(1);
// We shouldn't reject if:

View File

@ -148,10 +148,10 @@ void QNetworkDiskCache::setCacheDirectory(const QString &cacheDir)
d->cacheDirectory = cacheDir;
QDir dir(d->cacheDirectory);
d->cacheDirectory = dir.absolutePath();
if (!d->cacheDirectory.endsWith(QLatin1Char('/')))
d->cacheDirectory += QLatin1Char('/');
if (!d->cacheDirectory.endsWith(u'/'))
d->cacheDirectory += u'/';
d->dataDirectory = d->cacheDirectory + DATA_DIR + QString::number(CACHE_VERSION) + QLatin1Char('/');
d->dataDirectory = d->cacheDirectory + DATA_DIR + QString::number(CACHE_VERSION) + u'/';
d->prepareLayout();
}
@ -598,8 +598,7 @@ QString QNetworkDiskCachePrivate::uniqueFileName(const QUrl &url)
const QByteArray id = QByteArray::number(*(qlonglong*)hash.data(), 36).left(8);
// generates <one-char subdir>/<8-char filname.d>
uint code = (uint)id.at(id.length()-1) % 16;
QString pathFragment = QString::number(code, 16) + QLatin1Char('/')
+ QLatin1String(id) + CACHE_POSTFIX;
QString pathFragment = QString::number(code, 16) + u'/' + QLatin1String(id) + CACHE_POSTFIX;
return pathFragment;
}

View File

@ -105,7 +105,7 @@ QNetworkReplyFileImpl::QNetworkReplyFileImpl(QNetworkAccessManager *manager, con
if (fileName.isEmpty()) {
const QString scheme = url.scheme();
if (scheme == QLatin1String("qrc")) {
fileName = QLatin1Char(':') + url.path();
fileName = u':' + url.path();
} else {
#if defined(Q_OS_ANDROID)
if (scheme == QLatin1String("assets"))

View File

@ -1529,7 +1529,7 @@ static QByteArray qNtlmPhase3(QAuthenticatorPrivate *ctx, const QByteArray& phas
Q_ASSERT(QNtlmPhase3BlockBase::Size == sizeof(QNtlmPhase3BlockBase));
// for kerberos style user@domain logins, NTLM domain string should be left empty
if (ctx->userDomain.isEmpty() && !ctx->extractedUser.contains(QLatin1Char('@'))) {
if (ctx->userDomain.isEmpty() && !ctx->extractedUser.contains(u'@')) {
offset = qEncodeNtlmString(pb.domain, offset, ch.targetNameStr, unicode);
pb.domainStr = ch.targetNameStr;
} else {

View File

@ -137,7 +137,7 @@ void QHostAddressPrivate::setAddress(const Q_IPV6ADDR &a_)
static bool parseIp6(const QString &address, QIPAddressUtils::IPv6Address &addr, QString *scopeId)
{
QStringView tmp(address);
int scopeIdPos = tmp.lastIndexOf(QLatin1Char('%'));
qsizetype scopeIdPos = tmp.lastIndexOf(u'%');
if (scopeIdPos != -1) {
*scopeId = tmp.mid(scopeIdPos + 1).toString();
tmp.chop(tmp.size() - scopeIdPos);
@ -155,7 +155,7 @@ bool QHostAddressPrivate::parse(const QString &ipString)
return false;
// All IPv6 addresses contain a ':', and may contain a '.'.
if (a.contains(QLatin1Char(':'))) {
if (a.contains(u':')) {
quint8 maybeIp6[16];
if (parseIp6(a, maybeIp6, &scopeId)) {
setAddress(maybeIp6);
@ -738,7 +738,7 @@ QString QHostAddress::toString() const
} else if (d->protocol == QHostAddress::IPv6Protocol) {
QIPAddressUtils::toString(s, d->a6.c);
if (!d->scopeId.isEmpty())
s.append(QLatin1Char('%') + d->scopeId);
s.append(u'%' + d->scopeId);
}
return s;
}
@ -1043,17 +1043,17 @@ QPair<QHostAddress, int> QHostAddress::parseSubnet(const QString &subnet)
if (subnet.isEmpty())
return invalid;
int slash = subnet.indexOf(QLatin1Char('/'));
qsizetype slash = subnet.indexOf(u'/');
QStringView netStr(subnet);
if (slash != -1)
netStr.truncate(slash);
int netmask = -1;
bool isIpv6 = netStr.contains(QLatin1Char(':'));
bool isIpv6 = netStr.contains(u':');
if (slash != -1) {
// is the netmask given in IP-form or in bit-count form?
if (!isIpv6 && subnet.indexOf(QLatin1Char('.'), slash + 1) != -1) {
if (!isIpv6 && subnet.indexOf(u'.', slash + 1) != -1) {
// IP-style, convert it to bit-count form
QHostAddress mask;
QNetmask parser;
@ -1089,7 +1089,7 @@ QPair<QHostAddress, int> QHostAddress::parseSubnet(const QString &subnet)
return invalid; // invalid netmask
// parse the address manually
auto parts = netStr.split(QLatin1Char('.'));
auto parts = netStr.split(u'.');
if (parts.isEmpty() || parts.count() > 4)
return invalid; // invalid IPv4 address

View File

@ -145,7 +145,7 @@ QString QNetworkInterfacePrivate::makeHwAddress(int len, uchar *data)
QChar *out = result.data();
for (int i = 0; i < len; ++i) {
if (i)
*out++ = QLatin1Char(':');
*out++ = u':';
*out++ = QLatin1Char(QtMiscUtils::toHexUpper(data[i] / 16));
*out++ = QLatin1Char(QtMiscUtils::toHexUpper(data[i] % 16));
}

View File

@ -1592,7 +1592,7 @@ QDebug operator<<(QDebug debug, const QNetworkProxy &proxy)
scaps << QStringLiteral("SctpTunnel");
if (caps & QNetworkProxy::SctpListeningCapability)
scaps << QStringLiteral("SctpListen");
debug << '[' << scaps.join(QLatin1Char(' ')) << ']';
debug << '[' << scaps.join(u' ') << ']';
return debug;
}

View File

@ -83,7 +83,7 @@ static bool isHostExcluded(CFDictionaryRef dict, const QString &host)
if (host.isEmpty())
return true;
bool isSimple = !host.contains(QLatin1Char('.')) && !host.contains(QLatin1Char(':'));
bool isSimple = !host.contains(u'.') && !host.contains(u':');
CFNumberRef excludeSimples;
if (isSimple &&
(excludeSimples = (CFNumberRef)CFDictionaryGetValue(dict, kSCPropNetProxiesExcludeSimpleHostnames))) {

View File

@ -82,11 +82,11 @@ static bool currentProcessIsService()
static QStringList splitSpaceSemicolon(const QString &source)
{
QStringList list;
int start = 0;
int end;
qsizetype start = 0;
qsizetype end;
while (true) {
int space = source.indexOf(QLatin1Char(' '), start);
int semicolon = source.indexOf(QLatin1Char(';'), start);
qsizetype space = source.indexOf(u' ', start);
qsizetype semicolon = source.indexOf(u';', start);
end = space;
if (semicolon != -1 && (end == -1 || semicolon < end))
end = semicolon;
@ -108,7 +108,7 @@ static bool isBypassed(const QString &host, const QStringList &bypassList)
if (host.isEmpty())
return false;
bool isSimple = !host.contains(QLatin1Char('.')) && !host.contains(QLatin1Char(':'));
bool isSimple = !host.contains(u'.') && !host.contains(u':');
QHostAddress ipAddress;
bool isIpAddress = ipAddress.setAddress(host);
@ -219,12 +219,12 @@ static QList<QNetworkProxy> parseServerList(const QNetworkProxyQuery &query, con
&& query.queryType() != QNetworkProxyQuery::TcpServer
&& query.queryType() != QNetworkProxyQuery::SctpServer;
for (const QString &entry : proxyList) {
int server = 0;
qsizetype server = 0;
QNetworkProxy::ProxyType proxyType = QNetworkProxy::HttpProxy;
quint16 port = 8080;
int pos = entry.indexOf(QLatin1Char('='));
qsizetype pos = entry.indexOf(u'=');
QStringView scheme;
QStringView protocolTag;
if (pos != -1) {
@ -253,7 +253,7 @@ static QList<QNetworkProxy> parseServerList(const QNetworkProxyQuery &query, con
}
}
pos = entry.indexOf(QLatin1Char(':'), server);
pos = entry.indexOf(u':', server);
if (pos != -1) {
bool ok;
uint value = QStringView{entry}.mid(pos + 1).toUInt(&ok);

View File

@ -974,7 +974,7 @@ void QAbstractSocketPrivate::_q_startConnecting(const QHostInfo &hostInfo)
if (i != 0) s += QLatin1String(", ");
s += addresses.at(i).toString();
}
s += QLatin1Char('}');
s += u'}';
qDebug("QAbstractSocketPrivate::_q_startConnecting(hostInfo == %s)", s.toLatin1().constData());
#endif

View File

@ -84,11 +84,11 @@ void QLocalServerPrivate::init()
bool QLocalServerPrivate::removeServer(const QString &name)
{
QString fileName;
if (name.startsWith(QLatin1Char('/'))) {
if (name.startsWith(u'/')) {
fileName = name;
} else {
fileName = QDir::cleanPath(QDir::tempPath());
fileName += QLatin1Char('/') + name;
fileName += u'/' + name;
}
if (QFile::exists(fileName))
return QFile::remove(fileName);
@ -105,11 +105,11 @@ bool QLocalServerPrivate::listen(const QString &requestedServerName)
// determine the full server path
if (options.testFlag(QLocalServer::AbstractNamespaceOption)
|| requestedServerName.startsWith(QLatin1Char('/'))) {
|| requestedServerName.startsWith(u'/')) {
fullServerName = requestedServerName;
} else {
fullServerName = QDir::cleanPath(QDir::tempPath());
fullServerName += QLatin1Char('/') + requestedServerName;
fullServerName += u'/' + requestedServerName;
}
serverName = requestedServerName;

View File

@ -68,11 +68,11 @@ static QString pathNameForConnection(const QString &connectingName,
QLocalSocket::SocketOptions options)
{
if (options.testFlag(QLocalSocket::AbstractNamespaceOption)
|| connectingName.startsWith(QLatin1Char('/'))) {
|| connectingName.startsWith(u'/')) {
return connectingName;
}
return QDir::tempPath() + QLatin1Char('/') + connectingName;
return QDir::tempPath() + u'/' + connectingName;
}
static QLocalSocket::SocketOptions optionsForPlatform(QLocalSocket::SocketOptions srcOptions)
@ -446,7 +446,7 @@ bool QLocalSocketPrivate::parseSockaddr(const struct ::sockaddr_un &addr,
fullServerName = name;
serverName = abstractNamespace
? name
: fullServerName.mid(fullServerName.lastIndexOf(QLatin1Char('/')) + 1);
: fullServerName.mid(fullServerName.lastIndexOf(u'/') + 1);
if (serverName.isEmpty())
serverName = fullServerName;
}

View File

@ -124,9 +124,9 @@ static QString dump(const QByteArray &buf)
{
QString data;
for (int i = 0; i < qMin<int>(MAX_DATA_DUMP, buf.size()); ++i) {
if (i) data += QLatin1Char(' ');
if (i) data += u' ';
uint val = (unsigned char)buf.at(i);
// data += QString("0x%1").arg(val, 3, 16, QLatin1Char('0'));
// data += QString("0x%1").arg(val, 3, 16, u'0');
data += QString::number(val);
}
if (buf.size() > MAX_DATA_DUMP)

View File

@ -658,7 +658,7 @@ QList<QSslCertificate> QSslCertificate::fromPath(const QString &path,
QString sourcePath = QDir::fromNativeSeparators(path);
// Find the path without the filename
QString pathPrefix = sourcePath.left(sourcePath.lastIndexOf(QLatin1Char('/')));
QString pathPrefix = sourcePath.left(sourcePath.lastIndexOf(u'/'));
// Check if the path contains any special chars
int pos = -1;
@ -677,7 +677,7 @@ QList<QSslCertificate> QSslCertificate::fromPath(const QString &path,
if (pos != -1) {
// there was a special char in the path so cut of the part containing that char.
pathPrefix = pathPrefix.left(pos);
const int lastIndexOfSlash = pathPrefix.lastIndexOf(QLatin1Char('/'));
const qsizetype lastIndexOfSlash = pathPrefix.lastIndexOf(u'/');
if (lastIndexOfSlash != -1)
pathPrefix = pathPrefix.left(lastIndexOfSlash);
else

View File

@ -634,7 +634,7 @@ void QSslConfiguration::setCiphers(const QString &ciphers)
{
auto *p = d.data();
p->ciphers.clear();
const auto cipherNames = ciphers.split(QLatin1Char(':'), Qt::SkipEmptyParts);
const auto cipherNames = ciphers.split(u':', Qt::SkipEmptyParts);
for (const QString &cipherName : cipherNames) {
QSslCipher cipher(cipherName);
if (!cipher.isNull())

View File

@ -3055,14 +3055,14 @@ bool QSslSocketPrivate::isMatchingHostname(const QSslCertificate &cert, const QS
*/
bool QSslSocketPrivate::isMatchingHostname(const QString &cn, const QString &hostname)
{
int wildcard = cn.indexOf(QLatin1Char('*'));
qsizetype wildcard = cn.indexOf(u'*');
// Check this is a wildcard cert, if not then just compare the strings
if (wildcard < 0)
return QLatin1String(QUrl::toAce(cn)) == hostname;
int firstCnDot = cn.indexOf(QLatin1Char('.'));
int secondCnDot = cn.indexOf(QLatin1Char('.'), firstCnDot+1);
qsizetype firstCnDot = cn.indexOf(u'.');
qsizetype secondCnDot = cn.indexOf(u'.', firstCnDot+1);
// Check at least 3 components
if ((-1 == secondCnDot) || (secondCnDot+1 >= cn.length()))
@ -3073,7 +3073,7 @@ bool QSslSocketPrivate::isMatchingHostname(const QString &cn, const QString &hos
return false;
// Check only one star
if (cn.lastIndexOf(QLatin1Char('*')) != wildcard)
if (cn.lastIndexOf(u'*') != wildcard)
return false;
// Reject wildcard character embedded within the A-labels or U-labels of an internationalized
@ -3086,7 +3086,7 @@ bool QSslSocketPrivate::isMatchingHostname(const QString &cn, const QString &hos
return false;
// Check characters following first . match
int hnDot = hostname.indexOf(QLatin1Char('.'));
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)))) {
return false;

View File

@ -806,7 +806,7 @@ QSslCipher QTlsBackend::createCiphersuite(const QString &descriptionOneLine, int
{
QSslCipher ciph;
const auto descriptionList = QStringView{descriptionOneLine}.split(QLatin1Char(' '), Qt::SkipEmptyParts);
const auto descriptionList = QStringView{descriptionOneLine}.split(u' ', Qt::SkipEmptyParts);
if (descriptionList.size() > 5) {
ciph.d->isNull = false;
ciph.d->name = descriptionList.at(0).toString();
@ -868,7 +868,7 @@ QSslCipher QTlsBackend::createCiphersuite(const QString &suiteName, QSsl::SslPro
ciph.d->protocol = protocol;
ciph.d->protocolString = protocolString;
const auto bits = QStringView{ciph.d->name}.split(QLatin1Char('-'));
const auto bits = QStringView{ciph.d->name}.split(u'-');
if (bits.size() >= 2) {
if (bits.size() == 2 || bits.size() == 3)
ciph.d->keyExchangeMethod = QLatin1String("RSA");

View File

@ -583,8 +583,8 @@ struct LibGreaterThan
typedef bool result_type;
result_type operator()(QStringView lhs, QStringView rhs) const
{
const auto lhsparts = lhs.split(QLatin1Char('.'));
const auto rhsparts = rhs.split(QLatin1Char('.'));
const auto lhsparts = lhs.split(u'.');
const auto rhsparts = rhs.split(u'.');
Q_ASSERT(lhsparts.count() > 1 && rhsparts.count() > 1);
// note: checking rhs < lhs, the same as lhs > rhs
@ -615,8 +615,7 @@ static QStringList libraryPathList()
{
QStringList paths;
# ifdef Q_OS_DARWIN
paths = QString::fromLatin1(qgetenv("DYLD_LIBRARY_PATH"))
.split(QLatin1Char(':'), Qt::SkipEmptyParts);
paths = QString::fromLatin1(qgetenv("DYLD_LIBRARY_PATH")).split(u':', Qt::SkipEmptyParts);
// search in .app/Contents/Frameworks
UInt32 packageType;
@ -627,8 +626,7 @@ static QStringList libraryPathList()
paths << bundleUrl.resolved(frameworksUrl).path();
}
# else
paths = QString::fromLatin1(qgetenv("LD_LIBRARY_PATH"))
.split(QLatin1Char(':'), Qt::SkipEmptyParts);
paths = QString::fromLatin1(qgetenv("LD_LIBRARY_PATH")).split(u':', Qt::SkipEmptyParts);
# endif
paths << QLatin1String("/lib") << QLatin1String("/usr/lib") << QLatin1String("/usr/local/lib");
paths << QLatin1String("/lib64") << QLatin1String("/usr/lib64") << QLatin1String("/usr/local/lib64");
@ -659,7 +657,7 @@ static QStringList findAllLibs(QLatin1String filter)
std::sort(entryList.begin(), entryList.end(), LibGreaterThan());
for (const QString &entry : qAsConst(entryList))
found << path + QLatin1Char('/') + entry;
found << path + u'/' + entry;
}
return found;