summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qchar.cpp100
-rw-r--r--src/corelib/tools/qchar.h19
-rw-r--r--src/corelib/tools/qunicodetables_p.h14
3 files changed, 87 insertions, 46 deletions
diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp
index 138c3a69ee..9c5a515dd7 100644
--- a/src/corelib/tools/qchar.cpp
+++ b/src/corelib/tools/qchar.cpp
@@ -377,6 +377,7 @@ QT_BEGIN_NAMESPACE
\value ByteOrderSwapped
\value ParagraphSeparator
\value LineSeparator
+ \value LastValidCodePoint
*/
/*!
@@ -499,7 +500,7 @@ QT_BEGIN_NAMESPACE
*/
bool QChar::isPrint(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return false;
const int test = FLAG(Other_Control) |
FLAG(Other_Format) |
@@ -532,7 +533,7 @@ bool QChar::isPrint(uint ucs4)
*/
bool QT_FASTCALL QChar::isSpace_helper(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return false;
const int test = FLAG(Separator_Space) |
FLAG(Separator_Line) |
@@ -558,7 +559,7 @@ bool QT_FASTCALL QChar::isSpace_helper(uint ucs4)
*/
bool QChar::isMark(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return false;
const int test = FLAG(Mark_NonSpacing) |
FLAG(Mark_SpacingCombining) |
@@ -582,7 +583,7 @@ bool QChar::isMark(uint ucs4)
*/
bool QChar::isPunct(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return false;
const int test = FLAG(Punctuation_Connector) |
FLAG(Punctuation_Dash) |
@@ -610,7 +611,7 @@ bool QChar::isPunct(uint ucs4)
*/
bool QChar::isSymbol(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return false;
const int test = FLAG(Symbol_Math) |
FLAG(Symbol_Currency) |
@@ -640,7 +641,7 @@ bool QChar::isSymbol(uint ucs4)
*/
bool QT_FASTCALL QChar::isLetter_helper(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return false;
const int test = FLAG(Letter_Uppercase) |
FLAG(Letter_Lowercase) |
@@ -675,7 +676,7 @@ bool QT_FASTCALL QChar::isLetter_helper(uint ucs4)
*/
bool QT_FASTCALL QChar::isNumber_helper(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return false;
const int test = FLAG(Number_DecimalDigit) |
FLAG(Number_Letter) |
@@ -704,7 +705,7 @@ bool QT_FASTCALL QChar::isNumber_helper(uint ucs4)
*/
bool QT_FASTCALL QChar::isLetterOrNumber_helper(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return false;
const int test = FLAG(Letter_Uppercase) |
FLAG(Letter_Lowercase) |
@@ -738,17 +739,54 @@ bool QT_FASTCALL QChar::isLetterOrNumber_helper(uint ucs4)
*/
/*!
+ \fn bool QChar::isNonCharacter() const
+ \since 5.0
+
+ Returns true if the QChar is a non-character; false otherwise.
+
+ Unicode has a certain number of code points that are classified
+ as "non-characters:" that is, they can be used for internal purposes
+ in applications but cannot be used for text interchange.
+ Those are the last two entries each Unicode Plane ([0xfffe..0xffff],
+ [0x1fffe..0x1ffff], etc.) as well as the entries in range [0xfdd0..0xfdef].
+*/
+
+/*!
\fn bool QChar::isHighSurrogate() const
Returns true if the QChar is the high part of a UTF16 surrogate
- (i.e. if it's code point in range [0xd800..0xdbff]).
+ (i.e. if its code point is in range [0xd800..0xdbff]); false otherwise.
*/
/*!
\fn bool QChar::isLowSurrogate() const
Returns true if the QChar is the low part of a UTF16 surrogate
- (i.e. if it's code point in range [0xdc00..0xdfff]).
+ (i.e. if its code point is in range [0xdc00..0xdfff]); false otherwise.
+*/
+
+/*!
+ \fn bool QChar::isSurrogate() const
+ \since 5.0
+
+ Returns true if the QChar contains a code point that is in either
+ the high or the low part of the UTF-16 surrogate range
+ (i.e. if its code point is in range [0xd800..0xdfff]); false otherwise.
+*/
+
+/*!
+ \fn static bool isNonCharacter(uint ucs4)
+ \overload
+ \since 5.0
+
+ Returns true if the UCS-4-encoded character specified by \a ucs4
+ is a non-character; false otherwise.
+
+ Unicode has a certain number of code points that are classified
+ as "non-characters:" that is, they can be used for internal purposes
+ in applications but cannot be used for text interchange.
+ Those are the last two entries each Unicode Plane ([0xfffe..0xffff],
+ [0x1fffe..0x1ffff], etc.) as well as the entries in range [0xfdd0..0xfdef].
*/
/*!
@@ -757,7 +795,7 @@ bool QT_FASTCALL QChar::isLetterOrNumber_helper(uint ucs4)
Returns true if the UCS-4-encoded character specified by \a ucs4
is the high part of a UTF16 surrogate
- (i.e. if it's code point in range [0xd800..0xdbff]).
+ (i.e. if its code point is in range [0xd800..0xdbff]); false otherwise.
*/
/*!
@@ -766,7 +804,18 @@ bool QT_FASTCALL QChar::isLetterOrNumber_helper(uint ucs4)
Returns true if the UCS-4-encoded character specified by \a ucs4
is the low part of a UTF16 surrogate
- (i.e. if it's code point in range [0xdc00..0xdfff]).
+ (i.e. if its code point is in range [0xdc00..0xdfff]); false otherwise.
+*/
+
+/*!
+ \fn static bool QChar::isSurrogate(uint ucs4)
+ \overload
+ \since 5.0
+
+ Returns true if the UCS-4-encoded character specified by \a ucs4
+ contains a code point that is in either the high or the low part of the
+ UTF-16 surrogate range (i.e. if its code point is in range [0xd800..0xdfff]);
+ false otherwise.
*/
/*!
@@ -774,7 +823,8 @@ bool QT_FASTCALL QChar::isLetterOrNumber_helper(uint ucs4)
Returns true if the UCS-4-encoded character specified by \a ucs4
can be split into the high and low parts of a UTF16 surrogate
- (i.e. if it's code point is greater than or equals to 0x10000).
+ (i.e. if its code point is greater than or equals to 0x10000);
+ false otherwise.
*/
/*!
@@ -818,7 +868,7 @@ bool QT_FASTCALL QChar::isLetterOrNumber_helper(uint ucs4)
*/
int QChar::digitValue(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return -1;
return qGetProp(ucs4)->digitValue;
}
@@ -835,7 +885,7 @@ int QChar::digitValue(uint ucs4)
*/
QChar::Category QChar::category(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return QChar::Other_NotAssigned;
return (QChar::Category) qGetProp(ucs4)->category;
}
@@ -852,7 +902,7 @@ QChar::Category QChar::category(uint ucs4)
*/
QChar::Direction QChar::direction(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return QChar::DirL;
return (QChar::Direction) qGetProp(ucs4)->direction;
}
@@ -871,7 +921,7 @@ QChar::Direction QChar::direction(uint ucs4)
*/
QChar::Joining QChar::joining(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return QChar::OtherJoining;
return (QChar::Joining) qGetProp(ucs4)->joining;
}
@@ -900,7 +950,7 @@ QChar::Joining QChar::joining(uint ucs4)
*/
bool QChar::hasMirrored(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return false;
return qGetProp(ucs4)->mirrorDiff != 0;
}
@@ -950,7 +1000,7 @@ bool QChar::hasMirrored(uint ucs4)
*/
uint QChar::mirroredChar(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return ucs4;
return ucs4 + qGetProp(ucs4)->mirrorDiff;
}
@@ -1060,7 +1110,7 @@ QChar::Decomposition QChar::decompositionTag(uint ucs4)
*/
unsigned char QChar::combiningClass(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return 0;
return (unsigned char) qGetProp(ucs4)->combiningClass;
}
@@ -1078,7 +1128,7 @@ unsigned char QChar::combiningClass(uint ucs4)
*/
QChar::UnicodeVersion QChar::unicodeVersion(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return QChar::Unicode_Unassigned;
return (QChar::UnicodeVersion) qGetProp(ucs4)->unicodeVersion;
}
@@ -1155,7 +1205,7 @@ static inline T toCaseFolded_helper(T uc)
*/
uint QChar::toLower(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return ucs4;
return toLowerCase_helper<uint>(ucs4);
}
@@ -1175,7 +1225,7 @@ uint QChar::toLower(uint ucs4)
*/
uint QChar::toUpper(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return ucs4;
return toUpperCase_helper<uint>(ucs4);
}
@@ -1195,7 +1245,7 @@ uint QChar::toUpper(uint ucs4)
*/
uint QChar::toTitleCase(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return ucs4;
return toTitleCase_helper<uint>(ucs4);
}
@@ -1236,7 +1286,7 @@ static inline ushort foldCase(ushort ch)
*/
uint QChar::toCaseFolded(uint ucs4)
{
- if (ucs4 > UNICODE_LAST_CODEPOINT)
+ if (ucs4 > LastValidCodePoint)
return ucs4;
return toCaseFolded_helper<uint>(ucs4);
}
diff --git a/src/corelib/tools/qchar.h b/src/corelib/tools/qchar.h
index 07333c9535..6c423859ec 100644
--- a/src/corelib/tools/qchar.h
+++ b/src/corelib/tools/qchar.h
@@ -73,7 +73,8 @@ public:
ByteOrderMark = 0xfeff,
ByteOrderSwapped = 0xfffe,
ParagraphSeparator = 0x2029,
- LineSeparator = 0x2028
+ LineSeparator = 0x2028,
+ LastValidCodePoint = 0x10ffff
};
Q_DECL_CONSTEXPR QChar() : ucs(0) {}
@@ -245,24 +246,28 @@ public:
inline bool isUpper() const { return QChar::isUpper(ucs); }
inline bool isTitleCase() const { return QChar::isTitleCase(ucs); }
- inline bool isHighSurrogate() const {
- return ((ucs & 0xfc00) == 0xd800);
- }
- inline bool isLowSurrogate() const {
- return ((ucs & 0xfc00) == 0xdc00);
- }
+ inline bool isNonCharacter() const { return QChar::isNonCharacter(ucs); }
+ inline bool isHighSurrogate() const { return QChar::isHighSurrogate(ucs); }
+ inline bool isLowSurrogate() const { return QChar::isLowSurrogate(ucs); }
+ inline bool isSurrogate() const { return QChar::isSurrogate(ucs); }
inline uchar cell() const { return uchar(ucs & 0xff); }
inline uchar row() const { return uchar((ucs>>8)&0xff); }
inline void setCell(uchar cell);
inline void setRow(uchar row);
+ static inline bool isNonCharacter(uint ucs4) {
+ return ucs4 >= 0xfdd0 && (ucs4 <= 0xfdef || (ucs4 & 0xfffe) == 0xfffe);
+ }
static inline bool isHighSurrogate(uint ucs4) {
return ((ucs4 & 0xfffffc00) == 0xd800);
}
static inline bool isLowSurrogate(uint ucs4) {
return ((ucs4 & 0xfffffc00) == 0xdc00);
}
+ static inline bool isSurrogate(uint ucs4) {
+ return (ucs4 - 0xd800u < 2048u);
+ }
static inline bool requiresSurrogates(uint ucs4) {
return (ucs4 >= 0x10000);
}
diff --git a/src/corelib/tools/qunicodetables_p.h b/src/corelib/tools/qunicodetables_p.h
index 15d5415b0b..293f03b94f 100644
--- a/src/corelib/tools/qunicodetables_p.h
+++ b/src/corelib/tools/qunicodetables_p.h
@@ -61,8 +61,6 @@ QT_BEGIN_NAMESPACE
#define UNICODE_DATA_VERSION QChar::Unicode_5_0
-#define UNICODE_LAST_CODEPOINT 0x10ffff
-
namespace QUnicodeTables {
struct Properties {
@@ -237,18 +235,6 @@ namespace QUnicodeTables {
inline int script(QChar ch)
{ return script(ch.unicode()); }
-
- inline bool isNonCharacter(uint ucs4)
- {
- // Noncharacter_Code_Point:
- // Unicode has a couple of "non-characters" that one can use internally,
- // but are not allowed to be used for text interchange.
- // Those are the last two entries each Unicode Plane (U+FFFE..U+FFFF,
- // U+1FFFE..U+1FFFF, etc.) as well as the entries in range U+FDD0..U+FDEF
-
- return ucs4 >= 0xfdd0 && (ucs4 <= 0xfdef || (ucs4 & 0xfffe) == 0xfffe);
- }
-
} // namespace QUnicodeTables
QT_END_NAMESPACE