From 50fefebc8403c0f293210c6dc5a98adb19776b76 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Sun, 8 Apr 2012 10:18:45 +0300 Subject: replace hardcoded values with a surrogate handling methods Change-Id: Iba079953c46a29404232d2dacbe0c90170097d51 Reviewed-by: Oswald Buddenhagen Reviewed-by: Lars Knoll --- tests/auto/corelib/tools/qchar/tst_qchar.cpp | 18 ++++++++---------- util/unicode/main.cpp | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp index 215f4c18f2..6632776a86 100644 --- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp +++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp @@ -543,10 +543,10 @@ void tst_QChar::decomposition() { QString str; - str += QChar( (0x1D157 - 0x10000) / 0x400 + 0xd800 ); - str += QChar( ((0x1D157 - 0x10000) % 0x400) + 0xdc00 ); - str += QChar( (0x1D165 - 0x10000) / 0x400 + 0xd800 ); - str += QChar( ((0x1D165 - 0x10000) % 0x400) + 0xdc00 ); + str += QChar(QChar::highSurrogate(0x1D157)); + str += QChar(QChar::lowSurrogate(0x1D157)); + str += QChar(QChar::highSurrogate(0x1D165)); + str += QChar(QChar::lowSurrogate(0x1D165)); QVERIFY(QChar::decomposition(0x1D15e) == str); } @@ -629,14 +629,12 @@ void tst_QChar::normalization_data() for (int j = 0; j < c.size(); ++j) { bool ok; uint uc = c.at(j).toInt(&ok, 16); - if (uc < 0x10000) + if (!QChar::requiresSurrogates(uc)) { columns[i].append(QChar(uc)); - else { + } else { // convert to utf16 - ushort high = QChar::highSurrogate(uc); - ushort low = QChar::lowSurrogate(uc); - columns[i].append(QChar(high)); - columns[i].append(QChar(low)); + columns[i].append(QChar(QChar::highSurrogate(uc))); + columns[i].append(QChar(QChar::lowSurrogate(uc))); } } } diff --git a/util/unicode/main.cpp b/util/unicode/main.cpp index 2b4a76363f..d769176c6f 100644 --- a/util/unicode/main.cpp +++ b/util/unicode/main.cpp @@ -465,7 +465,7 @@ static int appendToSpecialCaseMap(const QList &map) QList utf16map; for (int i = 0; i < map.size(); ++i) { int val = map.at(i); - if (val >= 0x10000) { + if (QChar::requiresSurrogates(val)) { utf16map << QChar::highSurrogate(val); utf16map << QChar::lowSurrogate(val); } else { @@ -789,7 +789,7 @@ static void readUnicodeData() qWarning() << "upperCaseDiff exceeded (" << hex << codepoint << "->" << upperCase << ")"; data.p.upperCaseDiff = diff; maxUpperCaseDiff = qMax(maxUpperCaseDiff, qAbs(diff)); - if (codepoint >= 0x10000 || upperCase >= 0x10000) { + if (QChar::requiresSurrogates(codepoint) || QChar::requiresSurrogates(upperCase)) { // if the conditions below doesn't hold anymore we need to modify our upper casing code Q_ASSERT(QChar::highSurrogate(codepoint) == QChar::highSurrogate(upperCase)); Q_ASSERT(QChar::lowSurrogate(codepoint) + diff == QChar::lowSurrogate(upperCase)); @@ -803,7 +803,7 @@ static void readUnicodeData() qWarning() << "lowerCaseDiff exceeded (" << hex << codepoint << "->" << lowerCase << ")"; data.p.lowerCaseDiff = diff; maxLowerCaseDiff = qMax(maxLowerCaseDiff, qAbs(diff)); - if (codepoint >= 0x10000 || lowerCase >= 0x10000) { + if (QChar::requiresSurrogates(codepoint) || QChar::requiresSurrogates(lowerCase)) { // if the conditions below doesn't hold anymore we need to modify our lower casing code Q_ASSERT(QChar::highSurrogate(codepoint) == QChar::highSurrogate(lowerCase)); Q_ASSERT(QChar::lowSurrogate(codepoint) + diff == QChar::lowSurrogate(lowerCase)); @@ -820,7 +820,7 @@ static void readUnicodeData() qWarning() << "titleCaseDiff exceeded (" << hex << codepoint << "->" << titleCase << ")"; data.p.titleCaseDiff = diff; maxTitleCaseDiff = qMax(maxTitleCaseDiff, qAbs(diff)); - if (codepoint >= 0x10000 || titleCase >= 0x10000) { + if (QChar::requiresSurrogates(codepoint) || QChar::requiresSurrogates(titleCase)) { // if the conditions below doesn't hold anymore we need to modify our title casing code Q_ASSERT(QChar::highSurrogate(codepoint) == QChar::highSurrogate(titleCase)); Q_ASSERT(QChar::lowSurrogate(codepoint) + diff == QChar::lowSurrogate(titleCase)); @@ -1253,7 +1253,7 @@ static void readSpecialCasing() // if the condition below doesn't hold anymore we need to modify our // lower/upper/title casing code and case folding code - Q_ASSERT(codepoint < 0x10000); + Q_ASSERT(!QChar::requiresSurrogates(codepoint)); // qDebug() << "codepoint" << hex << codepoint; // qDebug() << line; @@ -1359,7 +1359,7 @@ static void readCaseFolding() qWarning() << "caseFoldDiff exceeded (" << hex << codepoint << "->" << caseFolded << ")"; ud.p.caseFoldDiff = diff; maxCaseFoldDiff = qMax(maxCaseFoldDiff, qAbs(diff)); - if (codepoint >= 0x10000 || caseFolded >= 0x10000) { + if (QChar::requiresSurrogates(codepoint) || QChar::requiresSurrogates(caseFolded)) { // if the conditions below doesn't hold anymore we need to modify our case folding code Q_ASSERT(QChar::highSurrogate(codepoint) == QChar::highSurrogate(caseFolded)); Q_ASSERT(QChar::lowSurrogate(codepoint) + diff == QChar::lowSurrogate(caseFolded)); @@ -2317,11 +2317,11 @@ static QByteArray createCompositionInfo() if (!d.decomposition.isEmpty()) { int utf16Chars = 0; for (int j = 0; j < d.decomposition.size(); ++j) - utf16Chars += d.decomposition.at(j) >= 0x10000 ? 2 : 1; + utf16Chars += QChar::requiresSurrogates(d.decomposition.at(j)) ? 2 : 1; decompositions.append(d.decompositionType + (utf16Chars<<8)); for (int j = 0; j < d.decomposition.size(); ++j) { int code = d.decomposition.at(j); - if (code >= 0x10000) { + if (QChar::requiresSurrogates(code)) { // save as surrogate pair ushort high = QChar::highSurrogate(code); ushort low = QChar::lowSurrogate(code); @@ -2358,11 +2358,11 @@ static QByteArray createCompositionInfo() if (!d.decomposition.isEmpty()) { int utf16Chars = 0; for (int j = 0; j < d.decomposition.size(); ++j) - utf16Chars += d.decomposition.at(j) >= 0x10000 ? 2 : 1; + utf16Chars += QChar::requiresSurrogates(d.decomposition.at(j)) ? 2 : 1; decompositions.append(d.decompositionType + (utf16Chars<<8)); for (int j = 0; j < d.decomposition.size(); ++j) { int code = d.decomposition.at(j); - if (code >= 0x10000) { + if (QChar::requiresSurrogates(code)) { // save as surrogate pair ushort high = QChar::highSurrogate(code); ushort low = QChar::lowSurrogate(code); -- cgit v1.2.3