From 087cda285f8a743427fa40d12e354e9ab7d1d84e Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Mon, 16 Apr 2012 11:26:41 +0300 Subject: [PATCH] fix QChar::isPrint() returns an incorrect result. results are now equals to results of ICU's u_isprint() for the entire set of the Unicode code points Change-Id: I763f4b37cccd285eb01543d486f25bd7ea011241 Reviewed-by: Lars Knoll --- src/corelib/tools/qchar.cpp | 16 ++++++-- tests/auto/corelib/tools/qchar/tst_qchar.cpp | 59 +++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp index ef229fc..80233b4 100644 --- a/src/corelib/tools/qchar.cpp +++ b/src/corelib/tools/qchar.cpp @@ -108,8 +108,8 @@ QT_BEGIN_NAMESPACE The classification functions include functions like those in the standard C++ header \ (formerly \), but - operating on the full range of Unicode characters. They all - return true if the character is a certain type of character; + operating on the full range of Unicode characters, not just for the ASCII + range. They all return true if the character is a certain type of character; otherwise they return false. These classification functions are isNull() (returns true if the character is '\\0'), isPrint() (true if the character is any sort of printable character, @@ -118,7 +118,9 @@ QT_BEGIN_NAMESPACE sort of numeric character, not just 0-9), isLetterOrNumber(), and isDigit() (decimal digits). All of these are wrappers around category() which return the Unicode-defined category of each - character. + character. Some of these also calculate the derived properties + (i.e. isSpace() returns true if the character is of category + Separator_* or an exceptional code point from Other_Control category). QChar also provides direction(), which indicates the "natural" writing direction of this character. The joining() function @@ -153,6 +155,9 @@ QT_BEGIN_NAMESPACE to construct a QChar from an 8-bit \c char, and you will need to call toAscii() or toLatin1() to get the 8-bit value back. + For more information see + \l{http://www.unicode.org/ucd/}{"About the Unicode Character Database"}. + \sa Unicode, QString, QLatin1Char */ @@ -473,7 +478,7 @@ QT_BEGIN_NAMESPACE /*! Returns true if the character is a printable character; otherwise - returns false. This is any character not of category Cc or Cn. + returns false. This is any character not of category Other_*. Note that this gives no indication of whether the character is available in a particular font. @@ -481,6 +486,9 @@ QT_BEGIN_NAMESPACE bool QChar::isPrint() const { const int test = FLAG(Other_Control) | + FLAG(Other_Format) | + FLAG(Other_Surrogate) | + FLAG(Other_PrivateUse) | FLAG(Other_NotAssigned); return !(FLAG(qGetProp(ucs)->category) & test); } diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp index 14c43d0..56613a9 100644 --- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp +++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp @@ -276,8 +276,65 @@ void tst_QChar::isLetterOrNumber() void tst_QChar::isPrint() { + // noncharacters, reserved (General_Gategory =Cn) + QVERIFY(!QChar(0x2064).isPrint()); + QVERIFY(!QChar(0x2069).isPrint()); + QVERIFY(!QChar(0xfdd0).isPrint()); + QVERIFY(!QChar(0xfdef).isPrint()); + QVERIFY(!QChar(0xfff0).isPrint()); + QVERIFY(!QChar(0xfff8).isPrint()); + QVERIFY(!QChar(0xfffe).isPrint()); + QVERIFY(!QChar(0xffff).isPrint()); +/* + QVERIFY(!QChar::isPrint(0xe0000u)); + QVERIFY(!QChar::isPrint(0xe0002u)); + QVERIFY(!QChar::isPrint(0xe001fu)); + QVERIFY(!QChar::isPrint(0xe0080u)); + QVERIFY(!QChar::isPrint(0xe00ffu)); +*/ + + // Other_Default_Ignorable_Code_Point, Variation_Selector + QVERIFY(QChar(0x034f).isPrint()); + QVERIFY(QChar(0x115f).isPrint()); + QVERIFY(QChar(0x180b).isPrint()); + QVERIFY(QChar(0x180d).isPrint()); + QVERIFY(QChar(0x3164).isPrint()); + QVERIFY(QChar(0xfe00).isPrint()); + QVERIFY(QChar(0xfe0f).isPrint()); + QVERIFY(QChar(0xffa0).isPrint()); +/* + QVERIFY(QChar::isPrint(0xe0100u)); + QVERIFY(QChar::isPrint(0xe01efu)); +*/ + + // Cf, Cs, Cc, White_Space, Annotation Characters + QVERIFY(!QChar(0x0008).isPrint()); + QVERIFY(!QChar(0x000a).isPrint()); + QVERIFY(QChar(0x0020).isPrint()); + QVERIFY(QChar(0x00a0).isPrint()); + QVERIFY(!QChar(0x00ad).isPrint()); + QVERIFY(!QChar(0x0085).isPrint()); + QVERIFY(!QChar(0xd800).isPrint()); + QVERIFY(!QChar(0xdc00).isPrint()); + QVERIFY(!QChar(0xfeff).isPrint()); +/* + QVERIFY(!QChar::isPrint(0x1d173u)); +*/ + + QVERIFY(QChar('0').isPrint()); QVERIFY(QChar('A').isPrint()); - QVERIFY(!QChar(0x1aff).isPrint()); // General_Gategory =Cn + QVERIFY(QChar('a').isPrint()); + + QVERIFY(!QChar(0x0370).isPrint()); // assigned in 5.1 + QVERIFY(!QChar(0x0524).isPrint()); // assigned in 5.2 + QVERIFY(!QChar(0x0526).isPrint()); // assigned in 6.0 + QVERIFY(!QChar(0x08a0).isPrint()); // assigned in 6.1 + QVERIFY(!QChar(0x1aff).isPrint()); // not assigned + QVERIFY(!QChar(0x1e9e).isPrint()); // assigned in 5.1 +/* + QVERIFY(!QChar::isPrint(0x1b000u)); // assigned in 6.0 + QVERIFY(!QChar::isPrint(0x110d0u)); // assigned in 5.1 +*/ } void tst_QChar::isUpper() -- 2.7.4