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 <lars.knoll@nokia.com>
This commit is contained in:
Konstantin Ritt 2012-04-16 11:26:41 +03:00 committed by Qt by Nokia
parent b8d1abe65b
commit 087cda285f
2 changed files with 70 additions and 5 deletions

View File

@ -108,8 +108,8 @@ QT_BEGIN_NAMESPACE
The classification functions include functions like those in the
standard C++ header \<cctype\> (formerly \<ctype.h\>), 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);
}

View File

@ -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()