Port from container::count() and length() to size()

This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8:

  auto QtContainerClass = anyOf(
      expr(hasType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))))).bind(o),
      expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o));
  makeRule(cxxMemberCallExpr(on(QtContainerClass),
                             callee(cxxMethodDecl(hasAnyName({"count", "length"),
                                                  parameterCountIs(0))))),
           changeTo(cat(access(o, cat("size"), "()"))),
           cat("use 'size()' instead of 'count()/length()'"))

a.k.a qt-port-to-std-compatible-api with config Scope: 'Container',
with the extended set of container classes recognized.

Change-Id: Ibb3c96e7b98fc3c5586b947e91cdc19d26e56c80
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2022-10-05 07:47:02 +02:00
parent 8f58c5304e
commit 5ccbb879fa
4 changed files with 13 additions and 13 deletions

View File

@ -198,7 +198,7 @@ QList<quint16> QAbstractHttpServer::serverPorts()
{
QList<quint16> ports;
auto children = findChildren<QTcpServer *>();
ports.reserve(children.count());
ports.reserve(children.size());
std::transform(children.cbegin(), children.cend(), std::back_inserter(ports),
[](const QTcpServer *server) { return server->serverPort(); });
return ports;

View File

@ -63,7 +63,7 @@ bool QHttpServerRequestPrivate::parseRequestLine(QByteArrayView line)
const auto requestMethod = line.first(i);
i++;
while (i < line.length() && line[i] == ' ')
while (i < line.size() && line[i] == ' ')
i++;
auto j = line.indexOf(' ', i);
@ -73,16 +73,16 @@ bool QHttpServerRequestPrivate::parseRequestLine(QByteArrayView line)
const auto requestUrl = line.sliced(i, j - i);
i = j + 1;
while (i < line.length() && line[i] == ' ')
while (i < line.size() && line[i] == ' ')
i++;
if (i >= line.length())
if (i >= line.size())
return false;
j = line.indexOf(' ', i);
const auto protocol = j == -1 ? line.sliced(i) : line.sliced(i, j - i);
if (protocol.length() != 8 || !protocol.startsWith("HTTP"))
if (protocol.size() != 8 || !protocol.startsWith("HTTP"))
return false;
parser.setMajorVersion(protocol[5] - '0');
@ -143,7 +143,7 @@ qsizetype QHttpServerRequestPrivate::readRequestLine(QAbstractSocket *socket)
if (c == '\n') {
// remove the CR at the end
if (fragment.endsWith('\r')) {
fragment.truncate(fragment.length() - 1);
fragment.truncate(fragment.size() - 1);
}
bool ok = parseRequestLine(fragment);
state = State::ReadingHeader;
@ -211,8 +211,8 @@ qsizetype QHttpServerRequestPrivate::readHeader(QAbstractSocket *socket)
// there is another case: We have no headers. Then the fragment equals just the line
// ending
if ((fragment.length() == 2 && fragment.endsWith("\r\n"))
|| (fragment.length() == 1 && fragment.endsWith("\n")))
if ((fragment.size() == 2 && fragment.endsWith("\r\n"))
|| (fragment.size() == 1 && fragment.endsWith("\n")))
allHeaders = true;
}
}

View File

@ -146,7 +146,7 @@ void tst_QAbstractHttpServer::websocket()
auto s2 = makeWebSocket();
QSignalSpy newConnectionSpy(&server, &HttpServer::newWebSocketConnection);
QTRY_COMPARE(newConnectionSpy.count(), 2);
QTRY_COMPARE(newConnectionSpy.size(), 2);
server.nextPendingWebSocketConnection();
server.nextPendingWebSocketConnection();
delete s1;
@ -170,8 +170,8 @@ void tst_QAbstractHttpServer::servers()
auto tcpServer2 = new QTcpServer;
tcpServer2->listen();
server.bind(tcpServer2);
QTRY_COMPARE(server.servers().count(), 2);
QTRY_COMPARE(server.serverPorts().count(), 2);
QTRY_COMPARE(server.servers().size(), 2);
QTRY_COMPARE(server.serverPorts().size(), 2);
QTRY_COMPARE(server.servers().first(), tcpServer);
QTRY_COMPARE(server.serverPorts().first(), tcpServer->serverPort());
QTRY_COMPARE(server.servers().last(), tcpServer2);

View File

@ -203,7 +203,7 @@ void tst_QHttpServerResponder::writeFile()
QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), code);
QCOMPARE(reply->readAll().trimmed(), data);
QCOMPARE(spyDestroyIoDevice.count(), 1);
QCOMPARE(spyDestroyIoDevice.size(), 1);
}
void tst_QHttpServerResponder::writeFileExtraHeader()
@ -227,7 +227,7 @@ void tst_QHttpServerResponder::writeFileExtraHeader()
QCOMPARE(reply->header(QNetworkRequest::ServerHeader).toByteArray(), headerServerValue);
QCOMPARE(reply->readAll().trimmed(), "<html></html>");
QCOMPARE(spyDestroyIoDevice.count(), 1);
QCOMPARE(spyDestroyIoDevice.size(), 1);
}
void tst_QHttpServerResponder::writeByteArrayExtraHeader()