diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp index b68da9def4..5d4769d7f0 100644 --- a/src/corelib/tools/qchar.cpp +++ b/src/corelib/tools/qchar.cpp @@ -601,12 +601,19 @@ bool QChar::isLetterOrNumber() const } /*! + \fn bool QChar::isDigit() const + Returns true if the character is a decimal digit (Number_DecimalDigit); otherwise returns false. */ -bool QChar::isDigit() const + +/*! + \internal + \overload +*/ +bool QChar::isDigit(ushort ucs2) { - return (qGetProp(ucs)->category == Number_DecimalDigit); + return (qGetProp(ucs2)->category == Number_DecimalDigit); } /*! diff --git a/src/corelib/tools/qchar.h b/src/corelib/tools/qchar.h index 3efa5e511d..801cb7d699 100644 --- a/src/corelib/tools/qchar.h +++ b/src/corelib/tools/qchar.h @@ -237,7 +237,8 @@ public: bool isLetter() const; bool isNumber() const; bool isLetterOrNumber() const; - bool isDigit() const; + inline bool isDigit() const + { return (ucs <= '9' && ucs >= '0') || (ucs > 127 && isDigit(ucs)); } bool isSymbol() const; inline bool isLower() const { return (ucs >= 'a' && ucs <= 'z') @@ -315,6 +316,8 @@ public: static QString QT_FASTCALL decomposition(uint ucs4); private: + static bool QT_FASTCALL isDigit(ushort ucs2); + #ifdef QT_NO_CAST_FROM_ASCII QChar(char c); QChar(uchar c); diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp index 02807f38b3..5a2a4834db 100644 --- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp +++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp @@ -73,6 +73,8 @@ private slots: void toLower(); void toTitle(); void toCaseFolded(); + void isDigit_data(); + void isDigit(); void isPrint(); void isUpper(); void isLower(); @@ -223,6 +225,25 @@ void tst_QChar::toCaseFolded() QVERIFY(QChar::toCaseFolded((ushort)0xb5) == 0x3bc); } +void tst_QChar::isDigit_data() +{ + QTest::addColumn("ucs"); + QTest::addColumn("expected"); + + for (ushort ucs = 0; ucs < 256; ++ucs) { + bool isDigit = (ucs <= '9' && ucs >= '0'); + QString tag = QString::fromLatin1("0x%0").arg(QString::number(ucs, 16)); + QTest::newRow(tag.toLatin1()) << ucs << isDigit; + } +} + +void tst_QChar::isDigit() +{ + QFETCH(ushort, ucs); + QFETCH(bool, expected); + QCOMPARE(QChar(ucs).isDigit(), expected); +} + void tst_QChar::isPrint() { QVERIFY(QChar('A').isPrint());