summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qchar.cpp11
-rw-r--r--src/corelib/tools/qchar.h7
-rw-r--r--tests/auto/corelib/tools/qchar/tst_qchar.cpp29
3 files changed, 44 insertions, 3 deletions
diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp
index 5d4769d7f0..a1978037c1 100644
--- a/src/corelib/tools/qchar.cpp
+++ b/src/corelib/tools/qchar.cpp
@@ -556,17 +556,24 @@ bool QChar::isPunct() const
}
/*!
+ \fn bool QChar::isLetter() const
+
Returns true if the character is a letter (Letter_* categories);
otherwise returns false.
*/
-bool QChar::isLetter() const
+
+/*!
+ \internal
+ \overload
+*/
+bool QChar::isLetter(ushort ucs2)
{
const int test = FLAG(Letter_Uppercase) |
FLAG(Letter_Lowercase) |
FLAG(Letter_Titlecase) |
FLAG(Letter_Modifier) |
FLAG(Letter_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 801cb7d699..fc5a9b051d 100644
--- a/src/corelib/tools/qchar.h
+++ b/src/corelib/tools/qchar.h
@@ -234,7 +234,11 @@ public:
bool isPunct() const;
bool isSpace() const;
bool isMark() const;
- bool isLetter() const;
+ inline bool isLetter() const {
+ return (ucs >= 'a' && ucs <= 'z')
+ || (ucs <= 'Z' && ucs >= 'A')
+ || (ucs > 127 && isLetter(ucs));
+ }
bool isNumber() const;
bool isLetterOrNumber() const;
inline bool isDigit() const
@@ -317,6 +321,7 @@ public:
private:
static bool QT_FASTCALL isDigit(ushort ucs2);
+ static bool QT_FASTCALL isLetter(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 5a2a4834db..0c51422f75 100644
--- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp
+++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp
@@ -75,6 +75,8 @@ private slots:
void toCaseFolded();
void isDigit_data();
void isDigit();
+ void isLetter_data();
+ void isLetter();
void isPrint();
void isUpper();
void isLower();
@@ -244,6 +246,33 @@ void tst_QChar::isDigit()
QCOMPARE(QChar(ucs).isDigit(), expected);
}
+static bool isExpectedLetter(ushort ucs)
+{
+ return (ucs >= 'a' && ucs <= 'z') || (ucs >= 'A' && ucs <= 'Z')
+ || ucs == 0xAA || ucs == 0xB5 || ucs == 0xBA
+ || (ucs >= 0xC0 && ucs <= 0xD6)
+ || (ucs >= 0xD8 && ucs <= 0xF6)
+ || (ucs >= 0xF8 && ucs <= 0xFF);
+}
+
+void tst_QChar::isLetter_data()
+{
+ QTest::addColumn<ushort>("ucs");
+ QTest::addColumn<bool>("expected");
+
+ for (ushort ucs = 0; ucs < 256; ++ucs) {
+ QString tag = QString::fromLatin1("0x%0").arg(QString::number(ucs, 16));
+ QTest::newRow(tag.toLatin1()) << ucs << isExpectedLetter(ucs);
+ }
+}
+
+void tst_QChar::isLetter()
+{
+ QFETCH(ushort, ucs);
+ QFETCH(bool, expected);
+ QCOMPARE(QChar(ucs).isLetter(), expected);
+}
+
void tst_QChar::isPrint()
{
QVERIFY(QChar('A').isPrint());