QString: Add functions isUpper and isLower
[ChangeLog][QtCore][QString] Added the functions QString::isUpper and QString::isLower to check if a string contains only uppercase or only lowercase letters. Change-Id: I12d3a47d4605eb4514842071e80a9ba0723d4e01 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
8692f12e89
commit
bcd6de15ac
@ -4896,6 +4896,50 @@ bool QString::endsWith(QChar c, Qt::CaseSensitivity cs) const
|
||||
return qt_ends_with(*this, c, cs);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns \c true if the string only contains uppercase letters,
|
||||
otherwise returns \c false.
|
||||
\since 5.12
|
||||
|
||||
\sa QChar::isUpper(), isLower()
|
||||
*/
|
||||
bool QString::isUpper() const
|
||||
{
|
||||
if (isEmpty())
|
||||
return false;
|
||||
|
||||
const QChar *d = data();
|
||||
|
||||
for (int i = 0, max = size(); i < max; ++i) {
|
||||
if (!d[i].isUpper())
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns \c true if the string only contains lowercase letters,
|
||||
otherwise returns \c false.
|
||||
\since 5.12
|
||||
|
||||
\sa QChar::isLower(), isUpper()
|
||||
*/
|
||||
bool QString::isLower() const
|
||||
{
|
||||
if (isEmpty())
|
||||
return false;
|
||||
|
||||
const QChar *d = data();
|
||||
|
||||
for (int i = 0, max = size(); i < max; ++i) {
|
||||
if (!d[i].isLower())
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static QByteArray qt_convert_to_latin1(QStringView string);
|
||||
|
||||
QByteArray QString::toLatin1_helper(const QString &string)
|
||||
|
@ -409,6 +409,9 @@ public:
|
||||
bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
||||
bool endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
||||
|
||||
bool isUpper() const;
|
||||
bool isLower() const;
|
||||
|
||||
Q_REQUIRED_RESULT QString leftJustified(int width, QChar fill = QLatin1Char(' '), bool trunc = false) const;
|
||||
Q_REQUIRED_RESULT QString rightJustified(int width, QChar fill = QLatin1Char(' '), bool trunc = false) const;
|
||||
|
||||
|
@ -452,6 +452,8 @@ private slots:
|
||||
void trimmed();
|
||||
void toUpper();
|
||||
void toLower();
|
||||
void isUpper();
|
||||
void isLower();
|
||||
void toCaseFolded();
|
||||
void rightJustified();
|
||||
void leftJustified();
|
||||
@ -2316,6 +2318,46 @@ void tst_QString::toLower()
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QString::isUpper()
|
||||
{
|
||||
QVERIFY(!QString().isUpper());
|
||||
QVERIFY(!QString("").isUpper());
|
||||
QVERIFY(QString("TEXT").isUpper());
|
||||
QVERIFY(!QString("text").isUpper());
|
||||
QVERIFY(!QString("Text").isUpper());
|
||||
QVERIFY(!QString("tExt").isUpper());
|
||||
QVERIFY(!QString("teXt").isUpper());
|
||||
QVERIFY(!QString("texT").isUpper());
|
||||
QVERIFY(!QString("TExt").isUpper());
|
||||
QVERIFY(!QString("teXT").isUpper());
|
||||
QVERIFY(!QString("tEXt").isUpper());
|
||||
QVERIFY(!QString("tExT").isUpper());
|
||||
QVERIFY(!QString("@ABYZ[").isUpper());
|
||||
QVERIFY(!QString("@abyz[").isUpper());
|
||||
QVERIFY(!QString("`ABYZ{").isUpper());
|
||||
QVERIFY(!QString("`abyz{").isUpper());
|
||||
}
|
||||
|
||||
void tst_QString::isLower()
|
||||
{
|
||||
QVERIFY(!QString().isLower());
|
||||
QVERIFY(!QString("").isLower());
|
||||
QVERIFY(QString("text").isLower());
|
||||
QVERIFY(!QString("Text").isLower());
|
||||
QVERIFY(!QString("tExt").isLower());
|
||||
QVERIFY(!QString("teXt").isLower());
|
||||
QVERIFY(!QString("texT").isLower());
|
||||
QVERIFY(!QString("TExt").isLower());
|
||||
QVERIFY(!QString("teXT").isLower());
|
||||
QVERIFY(!QString("tEXt").isLower());
|
||||
QVERIFY(!QString("tExT").isLower());
|
||||
QVERIFY(!QString("TEXT").isLower());
|
||||
QVERIFY(!QString("@ABYZ[").isLower());
|
||||
QVERIFY(!QString("@abyz[").isLower());
|
||||
QVERIFY(!QString("`ABYZ{").isLower());
|
||||
QVERIFY(!QString("`abyz{").isLower());
|
||||
}
|
||||
|
||||
void tst_QString::toCaseFolded()
|
||||
{
|
||||
QCOMPARE( QString().toCaseFolded(), QString() );
|
||||
|
Loading…
Reference in New Issue
Block a user