summaryrefslogtreecommitdiffstats
path: root/src/tools/tqstring.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/tqstring.cpp')
-rw-r--r--src/tools/tqstring.cpp22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/tools/tqstring.cpp b/src/tools/tqstring.cpp
index 318f1aa77..8db00f1cc 100644
--- a/src/tools/tqstring.cpp
+++ b/src/tools/tqstring.cpp
@@ -6016,13 +6016,10 @@ TQCString TQString::utf8() const
if ( u < 0x0800 ) {
*cursor++ = 0xc0 | ((uchar) (u >> 6));
} else {
- if (u >= 0xd800 && u < 0xdc00 && i < l-1) {
- unsigned short low = ch[1].unicode();
- if (low >= 0xdc00 && low < 0xe000) {
- ++ch;
- ++i;
- u = (u - 0xd800)*0x400 + (low - 0xdc00) + 0x10000;
- }
+ if (ch[0].isHighSurrogate() && i < (l - 1) && ch[1].isLowSurrogate()) {
+ u = TQChar::surrogateToUcs4(ch[0], ch[1]);
+ ++ch;
+ ++i;
}
if (u > 0xffff) {
// if people are working in utf8, but strings are encoded in eg. latin1, the resulting
@@ -6101,15 +6098,12 @@ TQString TQString::fromUtf8( const char* utf8, int len )
uc = (uc << 6) | (ch & 0x3f);
need--;
if ( !need ) {
- if (uc > 0xffff) {
+ if (TQChar::requiresSurrogates(uc)) {
// surrogate pair
- uc -= 0x10000;
- unsigned short high = uc/0x400 + 0xd800;
- unsigned short low = uc%0x400 + 0xdc00;
- *qch++ = TQChar(high);
- *qch++ = TQChar(low);
+ *qch++ = TQChar(TQChar::highSurrogate(uc));
+ *qch++ = TQChar(TQChar::lowSurrogate(uc));
} else if (uc < min_uc || (uc >= 0xd800 && uc <= 0xdfff) || (uc >= 0xfffe)) {
- // overlong seqence, UTF16 surrogate or BOM
+ // overlong sequence, UTF16 surrogate or BOM
i = error;
qch = addOne(qch, result);
*qch++ = TQChar(0xdbff);