From c5cda03125a6d34c179d968011083bceb87976bd Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Wed, 29 Jan 2025 18:05:37 +0900 Subject: Add support for surrogate pairs to TQChar API. This relates to issue #162. The new code is partially taken from Qt4 but with some local rework. Signed-off-by: Michele Calgaro --- src/codecs/tqgb18030codec.cpp | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'src/codecs/tqgb18030codec.cpp') diff --git a/src/codecs/tqgb18030codec.cpp b/src/codecs/tqgb18030codec.cpp index 0ae2fb4ff..d2578dc8e 100644 --- a/src/codecs/tqgb18030codec.cpp +++ b/src/codecs/tqgb18030codec.cpp @@ -184,18 +184,16 @@ TQCString TQGb18030Codec::fromUnicode(const TQString& uc, int& lenInOut) const if ( ch.row() == 0x00 && ch.cell() < 0x80 ) { // ASCII *cursor++ = ch.cell(); - } else if ((ch.unicode() & 0xf800) == 0xd800) { - unsigned short high = ch.unicode(); + } else if (ch.isHighSurrogate()) { // surrogates area. check for correct encoding // we need at least one more character, first the high surrogate, then the low one - if (i == l-1 || high >= 0xdc00) + if (i == l-1) *cursor++ = '?'; else { - unsigned short low = uc[i+1].unicode(); - if (low >= 0xdc00 && low <= 0xdfff) { + if (uc[i+1].isLowSurrogate()) { // valid surrogate pair + uint u = TQChar::surrogateToUcs4(uc[i], uc[i + 1]); ++i; - uint u = (high-0xd800)*0x400+(low-0xdc00)+0x10000; len = qt_UnicodeToGb18030(u, buf); if (len >= 2) { for (int j=0; j