fix QChar::decompositionTag() returns wrong result for Hangul syllables
authorKonstantin Ritt <ritt.ks@gmail.com>
Mon, 16 Apr 2012 09:52:52 +0000 (12:52 +0300)
committerQt by Nokia <qt-info@nokia.com>
Tue, 17 Apr 2012 16:44:13 +0000 (18:44 +0200)
Change-Id: I28e7b14b6a90aa539f8a50107737a66b3484fc00
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
src/corelib/tools/qchar.cpp
tests/auto/corelib/tools/qchar/tst_qchar.cpp

index 80233b4..e3d6c60 100644 (file)
@@ -981,6 +981,8 @@ QChar::Decomposition QChar::decompositionTag(uint ucs4)
 {
     if (ucs4 > UNICODE_LAST_CODEPOINT)
         return QChar::NoDecomposition;
+    if (ucs4 >= Hangul_SBase && ucs4 < Hangul_SBase + Hangul_SCount)
+        return QChar::Canonical;
     const unsigned short index = GET_DECOMPOSITION_INDEX(ucs4);
     if (index == 0xffff)
         return QChar::NoDecomposition;
index 56613a9..1a56807 100644 (file)
@@ -608,6 +608,14 @@ void tst_QChar::mirroredChar()
 
 void tst_QChar::decomposition()
 {
+    // Hangul syllables
+    for (uint ucs = 0xac00; ucs <= 0xd7af; ++ucs) {
+        QChar::Decomposition expected = QChar::unicodeVersion(ucs) > QChar::Unicode_Unassigned ? QChar::Canonical : QChar::NoDecomposition;
+        QString desc = QString::fromLatin1("ucs = 0x%1, tag = %2, expected = %3")
+                .arg(QString::number(ucs, 16)).arg(QChar::decompositionTag(ucs)).arg(expected);
+        QVERIFY2(QChar::decompositionTag(ucs) == expected, desc.toLatin1());
+    }
+
     QVERIFY(QChar((ushort)0xa0).decompositionTag() == QChar::NoBreak);
     QVERIFY(QChar((ushort)0xa8).decompositionTag() == QChar::Compat);
     QVERIFY(QChar((ushort)0x41).decompositionTag() == QChar::NoDecomposition);
@@ -805,6 +813,25 @@ void tst_QChar::normalization_manual()
         QVERIFY(composed.normalized(QString::NormalizationForm_KD) == decomposed);
         QVERIFY(composed.normalized(QString::NormalizationForm_KC) == decomposed);
     }
+    {   // hangul
+        QString composed;
+        composed += QChar(0xc154);
+        composed += QChar(0x11f0);
+        QString decomposed;
+        decomposed += QChar(0x1109);
+        decomposed += QChar(0x1167);
+        decomposed += QChar(0x11f0);
+
+        QVERIFY(composed.normalized(QString::NormalizationForm_D) == decomposed);
+        QVERIFY(composed.normalized(QString::NormalizationForm_C) == composed);
+        QVERIFY(composed.normalized(QString::NormalizationForm_KD) == decomposed);
+        QVERIFY(composed.normalized(QString::NormalizationForm_KC) == composed);
+
+        QVERIFY(decomposed.normalized(QString::NormalizationForm_D) == decomposed);
+        QVERIFY(decomposed.normalized(QString::NormalizationForm_C) == composed);
+        QVERIFY(decomposed.normalized(QString::NormalizationForm_KD) == decomposed);
+        QVERIFY(decomposed.normalized(QString::NormalizationForm_KC) == composed);
+    }
 }
 
 void tst_QChar::normalizationCorrections()