From 3d745d7ded2ed8d52a8c6d9f7113bd6a61e13647 Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Mon, 3 May 2010 23:53:23 +0400 Subject: 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 --- src/corelib/tools/qchar.cpp | 31 +++++++++++++++++++++++++++++-- src/corelib/tools/qchar.h | 9 +++++++++ 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; } -- cgit v0.12