Deprecate {QString, QByteArray}::count()

And remove their uses.

[ChangeLog][QtCore][Deprecation Notice] Deprecated QString::count()
and QByteArray::count() that take no parameters, to avoid confusion
with the algorithm overloads of the same name. They can be replaced
by size() or length() methods.

Change-Id: I6541e3235ab58cf750d89568d66d3b1d9bbd4a04
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Sona Kurazyan 2022-03-04 15:56:34 +01:00
parent 28d2514428
commit 6585963583
16 changed files with 51 additions and 37 deletions

View File

@ -103,7 +103,7 @@ void XmlOutput::decreaseIndent()
QString XmlOutput::doConversion(const QString &text) QString XmlOutput::doConversion(const QString &text)
{ {
if (!text.count()) if (!text.size())
return QString(); return QString();
else if (conversion == NoConversion) else if (conversion == NoConversion)
return text; return text;
@ -112,10 +112,10 @@ QString XmlOutput::doConversion(const QString &text)
if (conversion == XMLConversion) { if (conversion == XMLConversion) {
// this is a way to escape characters that shouldn't be converted // this is a way to escape characters that shouldn't be converted
for (int i=0; i<text.count(); ++i) { for (int i=0; i<text.size(); ++i) {
const QChar c = text.at(i); const QChar c = text.at(i);
if (c == QLatin1Char('&')) { if (c == QLatin1Char('&')) {
if ( (i + 7) < text.count() && if ( (i + 7) < text.size() &&
text.at(i + 1) == QLatin1Char('#') && text.at(i + 1) == QLatin1Char('#') &&
text.at(i + 2) == QLatin1Char('x') && text.at(i + 2) == QLatin1Char('x') &&
text.at(i + 7) == QLatin1Char(';') ) { text.at(i + 7) == QLatin1Char(';') ) {
@ -184,9 +184,9 @@ XmlOutput& XmlOutput::operator<<(const xml_output& o)
addRaw(QString("\n%1<Import %2=\"%3\" />").arg(currentIndent).arg(o.xo_text).arg(o.xo_value)); addRaw(QString("\n%1<Import %2=\"%3\" />").arg(currentIndent).arg(o.xo_text).arg(o.xo_value));
break; break;
case tCloseTag: case tCloseTag:
if (o.xo_value.count()) if (o.xo_value.size())
closeAll(); closeAll();
else if (o.xo_text.count()) else if (o.xo_text.size())
closeTo(o.xo_text); closeTo(o.xo_text);
else else
closeTag(); closeTag();
@ -201,7 +201,7 @@ XmlOutput& XmlOutput::operator<<(const xml_output& o)
{ {
// Special case to be able to close tag in normal // Special case to be able to close tag in normal
// way ("</tag>", not "/>") without using addRaw().. // way ("</tag>", not "/>") without using addRaw()..
if (!o.xo_text.count()) { if (!o.xo_text.size()) {
closeOpen(); closeOpen();
break; break;
} }
@ -230,14 +230,14 @@ XmlOutput& XmlOutput::operator<<(const xml_output& o)
// Output functions ---------------------------------------------------------- // Output functions ----------------------------------------------------------
void XmlOutput::newTag(const QString &tag) void XmlOutput::newTag(const QString &tag)
{ {
Q_ASSERT_X(tag.count(), "XmlOutput", "Cannot open an empty tag"); Q_ASSERT_X(tag.size(), "XmlOutput", "Cannot open an empty tag");
newTagOpen(tag); newTagOpen(tag);
closeOpen(); closeOpen();
} }
void XmlOutput::newTagOpen(const QString &tag) void XmlOutput::newTagOpen(const QString &tag)
{ {
Q_ASSERT_X(tag.count(), "XmlOutput", "Cannot open an empty tag"); Q_ASSERT_X(tag.size(), "XmlOutput", "Cannot open an empty tag");
closeOpen(); closeOpen();
if (format == NewLine) if (format == NewLine)

View File

@ -112,7 +112,7 @@ int QLoggingRule::pass(QLatin1String cat, QtMsgType msgType) const
return (enabled ? 1 : -1); return (enabled ? 1 : -1);
} else if (flags == RightFilter) { } else if (flags == RightFilter) {
// matches right // matches right
if (idx == (cat.size() - category.count())) if (idx == (cat.size() - category.size()))
return (enabled ? 1 : -1); return (enabled ? 1 : -1);
} }
} }

View File

@ -2659,12 +2659,14 @@ qsizetype QByteArray::count(char ch) const
return static_cast<int>(countCharHelper(*this, ch)); return static_cast<int>(countCharHelper(*this, ch));
} }
#if QT_DEPRECATED_SINCE(6, 4)
/*! \fn qsizetype QByteArray::count() const /*! \fn qsizetype QByteArray::count() const
\deprecated [6.4] Use size() or length() instead.
\overload \overload
Same as size(). Same as size().
*/ */
#endif
/*! /*!
\fn int QByteArray::compare(QByteArrayView bv, Qt::CaseSensitivity cs = Qt::CaseSensitive) const \fn int QByteArray::compare(QByteArrayView bv, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
@ -4481,7 +4483,7 @@ static void q_fromPercentEncoding(QByteArray *ba, char percent)
const char *inputPtr = data; const char *inputPtr = data;
qsizetype i = 0; qsizetype i = 0;
qsizetype len = ba->count(); qsizetype len = ba->size();
qsizetype outlen = 0; qsizetype outlen = 0;
int a, b; int a, b;
char c; char c;
@ -4584,7 +4586,7 @@ static void q_toPercentEncoding(QByteArray *ba, const char *dontEncode, const ch
return; return;
QByteArray input = *ba; QByteArray input = *ba;
qsizetype len = input.count(); qsizetype len = input.size();
const char *inputData = input.constData(); const char *inputData = input.constData();
char *output = nullptr; char *output = nullptr;
qsizetype length = 0; qsizetype length = 0;

View File

@ -468,7 +468,10 @@ public:
inline std::string toStdString() const; inline std::string toStdString() const;
inline qsizetype size() const noexcept { return d->size; } inline qsizetype size() const noexcept { return d->size; }
#if QT_DEPRECATED_SINCE(6, 4)
QT_DEPRECATED_VERSION_X_6_4("Use size() or length() instead.")
inline qsizetype count() const noexcept { return size(); } inline qsizetype count() const noexcept { return size(); }
#endif
inline qsizetype length() const noexcept { return size(); } inline qsizetype length() const noexcept { return size(); }
bool isNull() const noexcept; bool isNull() const noexcept;

View File

@ -4671,13 +4671,14 @@ qsizetype QString::count(const QRegularExpression &re) const
} }
#endif // QT_CONFIG(regularexpression) #endif // QT_CONFIG(regularexpression)
#if QT_DEPRECATED_SINCE(6, 4)
/*! \fn qsizetype QString::count() const /*! \fn qsizetype QString::count() const
\deprecated [6.4] Use size() or length() instead.
\overload count() \overload count()
Same as size(). Same as size().
*/ */
#endif
/*! /*!
\enum QString::SectionFlag \enum QString::SectionFlag

View File

@ -466,7 +466,10 @@ public:
QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QString) QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QString)
void swap(QString &other) noexcept { d.swap(other.d); } void swap(QString &other) noexcept { d.swap(other.d); }
inline qsizetype size() const { return d.size; } inline qsizetype size() const { return d.size; }
#if QT_DEPRECATED_SINCE(6, 4)
QT_DEPRECATED_VERSION_X_6_4("Use size() or length() instead.")
inline qsizetype count() const { return d.size; } inline qsizetype count() const { return d.size; }
#endif
inline qsizetype length() const { return d.size; } inline qsizetype length() const { return d.size; }
inline bool isEmpty() const; inline bool isEmpty() const;
void resize(qsizetype size); void resize(qsizetype size);

View File

@ -367,7 +367,7 @@ static void parseCmdLine(QStringList &arguments)
if (!arg.startsWith(QLatin1Char('-'))) if (!arg.startsWith(QLatin1Char('-')))
continue; continue;
char c = arg.count() == 2 ? arg.at(1).toLatin1() : char(0); char c = arg.size() == 2 ? arg.at(1).toLatin1() : char(0);
switch (c) { switch (c) {
case 'P': case 'P':
flags |= QDBusConnection::ExportNonScriptableProperties; flags |= QDBusConnection::ExportNonScriptableProperties;

View File

@ -586,10 +586,10 @@ bool genVulkanFunctionsPC(const QList<VkSpecParser::Command> &commands,
devCmdWrapperStr += "#endif\n\n"; devCmdWrapperStr += "#endif\n\n";
} }
if (devCmdNamesStr.count() > 2) if (devCmdNamesStr.size() > 2)
devCmdNamesStr = devCmdNamesStr.left(devCmdNamesStr.count() - 2); devCmdNamesStr.chop(2);
if (instCmdNamesStr.count() > 2) if (instCmdNamesStr.size() > 2)
instCmdNamesStr = instCmdNamesStr.left(instCmdNamesStr.count() - 2); instCmdNamesStr.chop(2);
const QString str = const QString str =
QString::asprintf(s, preamble.get(licHeaderFn).constData(), QString::asprintf(s, preamble.get(licHeaderFn).constData(),

View File

@ -2515,7 +2515,12 @@ void tst_QByteArray::length()
QCOMPARE(src.length(), res); QCOMPARE(src.length(), res);
QCOMPARE(src.size(), res); QCOMPARE(src.size(), res);
#if QT_DEPRECATED_SINCE(6, 4)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
QCOMPARE(src.count(), res); QCOMPARE(src.count(), res);
QT_WARNING_POP
#endif
} }
void tst_QByteArray::length_data() void tst_QByteArray::length_data()

View File

@ -1084,7 +1084,7 @@ void tst_QTextLayout::defaultWordSeparators_data()
QString separators(".,:;-<>[](){}=/+%&^*"); QString separators(".,:;-<>[](){}=/+%&^*");
separators += QLatin1String("!?"); separators += QLatin1String("!?");
for (int i = 0; i < separators.count(); ++i) { for (int i = 0; i < separators.size(); ++i) {
QTest::newRow(QString::number(i).toLatin1().data()) QTest::newRow(QString::number(i).toLatin1().data())
<< QString::fromLatin1("abcd") + separators.at(i) + QString::fromLatin1("efgh") << QString::fromLatin1("abcd") + separators.at(i) + QString::fromLatin1("efgh")
<< 0 << 4; << 0 << 4;

View File

@ -2724,8 +2724,8 @@ void tst_QNetworkReply::postToHttpMultipart()
QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); // 200 Ok QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); // 200 Ok
QVERIFY(multiPart->boundary().count() > 20); // check that there is randomness after the "boundary_.oOo._" string QVERIFY(multiPart->boundary().size() > 20); // check that there is randomness after the "boundary_.oOo._" string
QVERIFY(multiPart->boundary().count() < 70); QVERIFY(multiPart->boundary().size() < 70);
QByteArray replyData = reply->readAll(); QByteArray replyData = reply->readAll();
expectedReplyData.prepend("content type: multipart/" + contentType + "; boundary=\"" + multiPart->boundary() + "\"\n"); expectedReplyData.prepend("content type: multipart/" + contentType + "; boundary=\"" + multiPart->boundary() + "\"\n");
@ -2812,8 +2812,8 @@ void tst_QNetworkReply::putToHttpMultipart()
QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); // 200 Ok QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); // 200 Ok
QVERIFY(multiPart->boundary().count() > 20); // check that there is randomness after the "boundary_.oOo._" string QVERIFY(multiPart->boundary().size() > 20); // check that there is randomness after the "boundary_.oOo._" string
QVERIFY(multiPart->boundary().count() < 70); QVERIFY(multiPart->boundary().size() < 70);
QByteArray replyData = reply->readAll(); QByteArray replyData = reply->readAll();
expectedReplyData.prepend("content type: multipart/" + contentType + "; boundary=\"" + multiPart->boundary() + "\"\n"); expectedReplyData.prepend("content type: multipart/" + contentType + "; boundary=\"" + multiPart->boundary() + "\"\n");
@ -3030,8 +3030,8 @@ void tst_QNetworkReply::postToHttpsMultipart()
QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); // 200 Ok QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); // 200 Ok
QVERIFY(multiPart->boundary().count() > 20); // check that there is randomness after the "boundary_.oOo._" string QVERIFY(multiPart->boundary().size() > 20); // check that there is randomness after the "boundary_.oOo._" string
QVERIFY(multiPart->boundary().count() < 70); QVERIFY(multiPart->boundary().size() < 70);
QByteArray replyData = reply->readAll(); QByteArray replyData = reply->readAll();
expectedReplyData.prepend("content type: multipart/" + contentType + "; boundary=\"" + multiPart->boundary() + "\"\n"); expectedReplyData.prepend("content type: multipart/" + contentType + "; boundary=\"" + multiPart->boundary() + "\"\n");
@ -9013,8 +9013,8 @@ void tst_QNetworkReply::ioHttpRedirectMultipartPost()
QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); // 200 OK QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); // 200 OK
QVERIFY(multiPart->boundary().count() > 20); // check that there is randomness after the "boundary_.oOo._" string QVERIFY(multiPart->boundary().size() > 20); // check that there is randomness after the "boundary_.oOo._" string
QVERIFY(multiPart->boundary().count() < 70); QVERIFY(multiPart->boundary().size() < 70);
QByteArray replyData = reply->readAll(); QByteArray replyData = reply->readAll();
expectedReplyData.prepend("content type: multipart/" + contentType + "; boundary=\"" + multiPart->boundary() + "\"\n"); expectedReplyData.prepend("content type: multipart/" + contentType + "; boundary=\"" + multiPart->boundary() + "\"\n");
@ -9179,7 +9179,7 @@ public slots:
} }
if (m_receivedData.length() > 0 && !m_expectedData.startsWith(m_receivedData)) { if (m_receivedData.length() > 0 && !m_expectedData.startsWith(m_receivedData)) {
// We had received some data but it is corrupt! // We had received some data but it is corrupt!
qDebug() << "CORRUPT" << m_receivedData.count(); qDebug() << "CORRUPT" << m_receivedData.size();
#if 0 // Use this to track down the pattern of the corruption and conclude the source #if 0 // Use this to track down the pattern of the corruption and conclude the source
QFile a("/tmp/corrupt"); QFile a("/tmp/corrupt");

View File

@ -844,9 +844,9 @@ void tst_QSqlQuery::oraClob()
QVERIFY_SQL(q, exec(QLatin1String("select bl, cl from %1 where id = 3").arg(clobby))); QVERIFY_SQL(q, exec(QLatin1String("select bl, cl from %1 where id = 3").arg(clobby)));
QVERIFY(q.next()); QVERIFY(q.next());
QCOMPARE(q.value(0).toString().count(), loong.count()); QCOMPARE(q.value(0).toString().size(), loong.size());
QVERIFY(q.value(0).toString() == loong); // Deliberately not QCOMPARE() as too long QVERIFY(q.value(0).toString() == loong); // Deliberately not QCOMPARE() as too long
QCOMPARE(q.value(1).toByteArray().count(), loong.toLatin1().count()); QCOMPARE(q.value(1).toByteArray().size(), loong.toLatin1().size());
QVERIFY(q.value(1).toByteArray() == loong.toLatin1()); // ditto QVERIFY(q.value(1).toByteArray() == loong.toLatin1()); // ditto
} }
@ -868,7 +868,7 @@ void tst_QSqlQuery::oraClobBatch()
QVERIFY_SQL(q, exec("select cl from " + clobBatch)); QVERIFY_SQL(q, exec("select cl from " + clobBatch));
QVERIFY(q.next()); QVERIFY(q.next());
QCOMPARE(q.value(0).toString().count(), longString.size()); QCOMPARE(q.value(0).toString().size(), longString.size());
QVERIFY(q.value(0).toString() == longString); // As above. deliberately not QCOMPARE(). QVERIFY(q.value(0).toString() == longString); // As above. deliberately not QCOMPARE().
} }

View File

@ -1288,9 +1288,9 @@ void tst_Moc::winNewline()
QVERIFY(f.open(QIODevice::ReadOnly)); // no QIODevice::Text! QVERIFY(f.open(QIODevice::ReadOnly)); // no QIODevice::Text!
QByteArray data = f.readAll(); QByteArray data = f.readAll();
f.close(); f.close();
for (int i = 0; i < data.count(); ++i) { for (int i = 0; i < data.size(); ++i) {
if (data.at(i) == QLatin1Char('\r')) { if (data.at(i) == QLatin1Char('\r')) {
QVERIFY(i < data.count() - 1); QVERIFY(i < data.size() - 1);
++i; ++i;
QCOMPARE(data.at(i), '\n'); QCOMPARE(data.at(i), '\n');
} else { } else {

View File

@ -530,7 +530,7 @@ void tst_QFiledialog::completer()
} }
// press 'keys' for the input // press 'keys' for the input
for (int i = 0; i < input.count(); ++i) for (int i = 0; i < input.size(); ++i)
QTest::keyPress(lineEdit, input[i].toLatin1()); QTest::keyPress(lineEdit, input[i].toLatin1());
QStringList expectedFiles; QStringList expectedFiles;

View File

@ -825,7 +825,7 @@ void tst_QFileDialog2::task203703_returnProperSeparator()
QVERIFY(button); QVERIFY(button);
QTest::keyClick(button, Qt::Key_Return); QTest::keyClick(button, Qt::Key_Return);
QString result = fd.selectedFiles().first(); QString result = fd.selectedFiles().first();
QVERIFY(result.at(result.count() - 1) != '/'); QVERIFY(result.at(result.size() - 1) != '/');
QVERIFY(!result.contains('\\')); QVERIFY(!result.contains('\\'));
current.rmdir("aaaaaaaaaaaaaaaaaa"); current.rmdir("aaaaaaaaaaaaaaaaaa");
} }

View File

@ -4019,7 +4019,7 @@ void tst_QWidget::restoreVersion1Geometry()
QVERIFY(f.exists()); QVERIFY(f.exists());
f.open(QIODevice::ReadOnly); f.open(QIODevice::ReadOnly);
const QByteArray savedGeometry = f.readAll(); const QByteArray savedGeometry = f.readAll();
QCOMPARE(savedGeometry.count(), 46); QCOMPARE(savedGeometry.size(), 46);
f.close(); f.close();
QWidget widget; QWidget widget;