diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp index a1978037c1e..56773bd527e 100644 --- a/src/corelib/tools/qchar.cpp +++ b/src/corelib/tools/qchar.cpp @@ -591,10 +591,17 @@ bool QChar::isNumber() const } /*! + \fn bool QChar::isLetterOrNumber() const + Returns true if the character is a letter or number (Letter_* or Number_* categories); otherwise returns false. */ -bool QChar::isLetterOrNumber() const + +/*! + \internal + \overload +*/ +bool QChar::isLetterOrNumber(ushort ucs2) { const int test = FLAG(Letter_Uppercase) | FLAG(Letter_Lowercase) | @@ -604,7 +611,7 @@ bool QChar::isLetterOrNumber() const FLAG(Number_DecimalDigit) | FLAG(Number_Letter) | FLAG(Number_Other); - return FLAG(qGetProp(ucs)->category) & test; + return FLAG(qGetProp(ucs2)->category) & test; } /*! diff --git a/src/corelib/tools/qchar.h b/src/corelib/tools/qchar.h index fc5a9b051de..36e185ebcea 100644 --- a/src/corelib/tools/qchar.h +++ b/src/corelib/tools/qchar.h @@ -240,7 +240,13 @@ public: || (ucs > 127 && isLetter(ucs)); } bool isNumber() const; - bool isLetterOrNumber() const; + inline bool isLetterOrNumber() const + { + return (ucs >= 'a' && ucs <= 'z') + || (ucs <= 'Z' && ucs >= 'A') + || (ucs <= '9' && ucs >= '0') + || (ucs > 127 && isLetterOrNumber(ucs)); + } inline bool isDigit() const { return (ucs <= '9' && ucs >= '0') || (ucs > 127 && isDigit(ucs)); } bool isSymbol() const; @@ -322,6 +328,7 @@ public: private: static bool QT_FASTCALL isDigit(ushort ucs2); static bool QT_FASTCALL isLetter(ushort ucs2); + static bool QT_FASTCALL isLetterOrNumber(ushort ucs2); #ifdef QT_NO_CAST_FROM_ASCII QChar(char c); diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp index 0c51422f75b..f16d32a4f9a 100644 --- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp +++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp @@ -77,6 +77,8 @@ private slots: void isDigit(); void isLetter_data(); void isLetter(); + void isLetterOrNumber_data(); + void isLetterOrNumber(); void isPrint(); void isUpper(); void isLower(); @@ -273,6 +275,28 @@ void tst_QChar::isLetter() QCOMPARE(QChar(ucs).isLetter(), expected); } +void tst_QChar::isLetterOrNumber_data() +{ + QTest::addColumn("ucs"); + QTest::addColumn("expected"); + + for (ushort ucs = 0; ucs < 256; ++ucs) { + bool isLetterOrNumber = isExpectedLetter(ucs) + || (ucs >= '0' && ucs <= '9') + || ucs == 0xB2 || ucs == 0xB3 || ucs == 0xB9 + || (ucs >= 0xBC && ucs <= 0xBE); + QString tag = QString::fromLatin1("0x%0").arg(QString::number(ucs, 16)); + QTest::newRow(tag.toLatin1()) << ucs << isLetterOrNumber; + } +} + +void tst_QChar::isLetterOrNumber() +{ + QFETCH(ushort, ucs); + QFETCH(bool, expected); + QCOMPARE(QChar(ucs).isLetterOrNumber(), expected); +} + void tst_QChar::isPrint() { QVERIFY(QChar('A').isPrint());