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)
{
if (!text.count())
if (!text.size())
return QString();
else if (conversion == NoConversion)
return text;
@ -112,10 +112,10 @@ QString XmlOutput::doConversion(const QString &text)
if (conversion == XMLConversion) {
// 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);
if (c == QLatin1Char('&')) {
if ( (i + 7) < text.count() &&
if ( (i + 7) < text.size() &&
text.at(i + 1) == QLatin1Char('#') &&
text.at(i + 2) == QLatin1Char('x') &&
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));
break;
case tCloseTag:
if (o.xo_value.count())
if (o.xo_value.size())
closeAll();
else if (o.xo_text.count())
else if (o.xo_text.size())
closeTo(o.xo_text);
else
closeTag();
@ -201,7 +201,7 @@ XmlOutput& XmlOutput::operator<<(const xml_output& o)
{
// Special case to be able to close tag in normal
// way ("</tag>", not "/>") without using addRaw()..
if (!o.xo_text.count()) {
if (!o.xo_text.size()) {
closeOpen();
break;
}
@ -230,14 +230,14 @@ XmlOutput& XmlOutput::operator<<(const xml_output& o)
// Output functions ----------------------------------------------------------
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);
closeOpen();
}
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();
if (format == NewLine)

View File

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

View File

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

View File

@ -468,7 +468,10 @@ public:
inline std::string toStdString() const;
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(); }
#endif
inline qsizetype length() const noexcept { return size(); }
bool isNull() const noexcept;

View File

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

View File

@ -466,7 +466,10 @@ public:
QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QString)
void swap(QString &other) noexcept { d.swap(other.d); }
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; }
#endif
inline qsizetype length() const { return d.size; }
inline bool isEmpty() const;
void resize(qsizetype size);

View File

@ -367,7 +367,7 @@ static void parseCmdLine(QStringList &arguments)
if (!arg.startsWith(QLatin1Char('-')))
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) {
case 'P':
flags |= QDBusConnection::ExportNonScriptableProperties;

View File

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

View File

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

View File

@ -1084,7 +1084,7 @@ void tst_QTextLayout::defaultWordSeparators_data()
QString separators(".,:;-<>[](){}=/+%&^*");
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())
<< QString::fromLatin1("abcd") + separators.at(i) + QString::fromLatin1("efgh")
<< 0 << 4;

View File

@ -2724,8 +2724,8 @@ void tst_QNetworkReply::postToHttpMultipart()
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().count() < 70);
QVERIFY(multiPart->boundary().size() > 20); // check that there is randomness after the "boundary_.oOo._" string
QVERIFY(multiPart->boundary().size() < 70);
QByteArray replyData = reply->readAll();
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
QVERIFY(multiPart->boundary().count() > 20); // check that there is randomness after the "boundary_.oOo._" string
QVERIFY(multiPart->boundary().count() < 70);
QVERIFY(multiPart->boundary().size() > 20); // check that there is randomness after the "boundary_.oOo._" string
QVERIFY(multiPart->boundary().size() < 70);
QByteArray replyData = reply->readAll();
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
QVERIFY(multiPart->boundary().count() > 20); // check that there is randomness after the "boundary_.oOo._" string
QVERIFY(multiPart->boundary().count() < 70);
QVERIFY(multiPart->boundary().size() > 20); // check that there is randomness after the "boundary_.oOo._" string
QVERIFY(multiPart->boundary().size() < 70);
QByteArray replyData = reply->readAll();
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
QVERIFY(multiPart->boundary().count() > 20); // check that there is randomness after the "boundary_.oOo._" string
QVERIFY(multiPart->boundary().count() < 70);
QVERIFY(multiPart->boundary().size() > 20); // check that there is randomness after the "boundary_.oOo._" string
QVERIFY(multiPart->boundary().size() < 70);
QByteArray replyData = reply->readAll();
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)) {
// 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
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(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
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
}
@ -868,7 +868,7 @@ void tst_QSqlQuery::oraClobBatch()
QVERIFY_SQL(q, exec("select cl from " + clobBatch));
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().
}

View File

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

View File

@ -530,7 +530,7 @@ void tst_QFiledialog::completer()
}
// 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());
QStringList expectedFiles;

View File

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

View File

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