summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRitt Konstantin <ritt.ks@gmail.com>2010-05-03 19:53:23 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2010-05-03 19:04:25 (GMT)
commit3d745d7ded2ed8d52a8c6d9f7113bd6a61e13647 (patch)
treede1ed35b10f4433326b614a1ebd732425a0839b5
parent7b3092423dc4b6c66aa34c483e6ede2e22747159 (diff)
downloadQt-3d745d7ded2ed8d52a8c6d9f7113bd6a61e13647.zip
Qt-3d745d7ded2ed8d52a8c6d9f7113bd6a61e13647.tar.gz
Qt-3d745d7ded2ed8d52a8c6d9f7113bd6a61e13647.tar.bz2
add static QChar::is(High|Low)Surrogate methods
to avoid recoding of character this also adds QChar::requiresSurrogates() static member supposed to save from common mistake like `ucs4 > 0x10000` Merge-request: 606 Reviewed-by: Thiago Macieira <thiago.macieira@nokia.com>
-rw-r--r--src/corelib/tools/qchar.cpp31
-rw-r--r--src/corelib/tools/qchar.h9
2 files changed, 38 insertions, 2 deletions
diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp
index 67ea00d..2f09b0e 100644
--- a/src/corelib/tools/qchar.cpp
+++ b/src/corelib/tools/qchar.cpp
@@ -653,14 +653,41 @@ bool QChar::isSymbol() const
\fn bool QChar::isHighSurrogate() const
Returns true if the QChar is the high part of a utf16 surrogate
- (ie. if its code point is between 0xd800 and 0xdbff).
+ (ie. if its code point is between 0xd800 and 0xdbff, inclusive).
*/
/*!
\fn bool QChar::isLowSurrogate() const
Returns true if the QChar is the low part of a utf16 surrogate
- (ie. if its code point is between 0xdc00 and 0xdfff).
+ (ie. if its code point is between 0xdc00 and 0xdfff, inclusive).
+*/
+
+/*!
+ \fn static bool QChar::isHighSurrogate(uint ucs4)
+ \since 4.7
+
+ Returns true if the UCS-4-encoded character specified by \a ucs4
+ is the high part of a utf16 surrogate
+ (ie. if its code point is between 0xd800 and 0xdbff, inclusive).
+*/
+
+/*!
+ \fn static bool QChar::isLowSurrogate(uint ucs4)
+ \since 4.7
+
+ Returns true if the UCS-4-encoded character specified by \a ucs4
+ is the high part of a utf16 surrogate
+ (ie. if its code point is between 0xdc00 and 0xdfff, inclusive).
+*/
+
+/*!
+ \fn static bool QChar::requiresSurrogates(uint ucs4)
+ \since 4.7
+
+ Returns true if the UCS-4-encoded character specified by \a ucs4
+ can be splited to the high and low parts of a utf16 surrogate
+ (ie. if its code point is greater than or equals to 0x10000).
*/
/*!
diff --git a/src/corelib/tools/qchar.h b/src/corelib/tools/qchar.h
index 1432c7f..205f911 100644
--- a/src/corelib/tools/qchar.h
+++ b/src/corelib/tools/qchar.h
@@ -285,6 +285,15 @@ public:
inline void setCell(uchar cell);
inline void setRow(uchar row);
+ static inline bool isHighSurrogate(uint ucs4) {
+ return ((ucs4 & 0xfffffc00) == 0xd800);
+ }
+ static inline bool isLowSurrogate(uint ucs4) {
+ return ((ucs4 & 0xfffffc00) == 0xdc00);
+ }
+ static inline bool requiresSurrogates(uint ucs4) {
+ return (ucs4 >= 0x10000);
+ }
static inline uint surrogateToUcs4(ushort high, ushort low) {
return (uint(high)<<10) + low - 0x35fdc00;
}