QHttpHeaderParser: fix clang-tidy nags

"use empty instead of checking size"
"no else following return"
"initialize your variables"

Change-Id: I4512471ec15a00f7ac1fccf88a3c87b8aa983ad7
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Mårten Nordheim 2022-06-17 14:49:16 +02:00
parent e3ea1d02e6
commit f5138d3065

View File

@ -31,7 +31,7 @@ static bool fieldNameCheck(QByteArrayView name)
|| otherCharacters.contains(c); || otherCharacters.contains(c);
}; };
return name.size() > 0 && std::all_of(name.begin(), name.end(), fieldNameChar); return !name.empty() && std::all_of(name.begin(), name.end(), fieldNameChar);
} }
bool QHttpHeaderParser::parseHeaders(QByteArrayView header) bool QHttpHeaderParser::parseHeaders(QByteArrayView header)
@ -43,7 +43,7 @@ bool QHttpHeaderParser::parseHeaders(QByteArrayView header)
return h.startsWith(' ') || h.startsWith('\t'); return h.startsWith(' ') || h.startsWith('\t');
}; };
// Headers, if non-empty, start with a non-space and end with a newline: // Headers, if non-empty, start with a non-space and end with a newline:
if (hSpaceStart(header) || (header.size() && !header.endsWith('\n'))) if (hSpaceStart(header) || (!header.empty() && !header.endsWith('\n')))
return false; return false;
while (int tail = header.endsWith("\n\r\n") ? 2 : header.endsWith("\n\n") ? 1 : 0) while (int tail = header.endsWith("\n\r\n") ? 2 : header.endsWith("\n\n") ? 1 : 0)
@ -53,10 +53,10 @@ bool QHttpHeaderParser::parseHeaders(QByteArrayView header)
return false; return false;
QList<QPair<QByteArray, QByteArray>> result; QList<QPair<QByteArray, QByteArray>> result;
while (header.size()) { while (!header.empty()) {
const int colon = header.indexOf(':'); const int colon = header.indexOf(':');
if (colon == -1) // if no colon check if empty headers if (colon == -1) // if no colon check if empty headers
return result.size() == 0 && (header == "\n" || header == "\r\n"); return result.empty() && (header == "\n" || header == "\r\n");
if (result.size() >= maxFieldCount) if (result.size() >= maxFieldCount)
return false; return false;
QByteArrayView name = header.first(colon); QByteArrayView name = header.first(colon);
@ -73,7 +73,7 @@ bool QHttpHeaderParser::parseHeaders(QByteArrayView header)
if (valueSpace < 0) if (valueSpace < 0)
return false; return false;
line = line.trimmed(); line = line.trimmed();
if (line.size()) { if (!line.empty()) {
if (value.size()) if (value.size())
value += ' ' + line.toByteArray(); value += ' ' + line.toByteArray();
else else
@ -119,7 +119,7 @@ bool QHttpHeaderParser::parseStatus(QByteArrayView status)
const QByteArrayView code = j > i ? status.sliced(i + 1, j - i - 1) const QByteArrayView code = j > i ? status.sliced(i + 1, j - i - 1)
: status.sliced(i + 1); : status.sliced(i + 1);
bool ok; bool ok = false;
statusCode = code.toInt(&ok); statusCode = code.toInt(&ok);
reasonPhrase = j > i ? QString::fromLatin1(status.sliced(j + 1)) reasonPhrase = j > i ? QString::fromLatin1(status.sliced(j + 1))
@ -148,8 +148,7 @@ QByteArray QHttpHeaderParser::combinedHeaderValue(const QByteArray &name, const
const QList<QByteArray> allValues = headerFieldValues(name); const QList<QByteArray> allValues = headerFieldValues(name);
if (allValues.isEmpty()) if (allValues.isEmpty())
return defaultValue; return defaultValue;
else return allValues.join(", ");
return allValues.join(", ");
} }
QList<QByteArray> QHttpHeaderParser::headerFieldValues(const QByteArray &name) const QList<QByteArray> QHttpHeaderParser::headerFieldValues(const QByteArray &name) const