Fix a bug in the case conversion code
authorLars Knoll <lars.knoll@nokia.com>
Thu, 31 May 2012 14:43:45 +0000 (16:43 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 1 Jun 2012 11:11:50 +0000 (13:11 +0200)
Chars that have a case conversion that converts
them into several characters can't be handled
by QChar::toUpper() etc and should get ignored. The code
didn't do that correctly.

Change-Id: I281d122e90bf49187b6449088d2fccef2ef75e86
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
src/corelib/tools/qchar.cpp
tests/auto/corelib/tools/qchar/tst_qchar.cpp

index ecaeff4..f7744ee 100644 (file)
@@ -1152,8 +1152,7 @@ static inline T toLowerCase_helper(T uc)
     const QUnicodeTables::Properties *p = qGetProp(uc);
     if (p->lowerCaseSpecial) {
         const ushort *specialCase = specialCaseMap + p->lowerCaseDiff;
-        if (*specialCase == 1)
-            return specialCase[1];
+        return (*specialCase == 1) ? specialCase[1] : uc;
     }
     return uc + p->lowerCaseDiff;
 }
@@ -1164,8 +1163,7 @@ static inline T toUpperCase_helper(T uc)
     const QUnicodeTables::Properties *p = qGetProp(uc);
     if (p->upperCaseSpecial) {
         const ushort *specialCase = specialCaseMap + p->upperCaseDiff;
-        if (*specialCase == 1)
-            return specialCase[1];
+        return (*specialCase == 1) ? specialCase[1] : uc;
     }
     return uc + p->upperCaseDiff;
 }
@@ -1176,8 +1174,7 @@ static inline T toTitleCase_helper(T uc)
     const QUnicodeTables::Properties *p = qGetProp(uc);
     if (p->titleCaseSpecial) {
         const ushort *specialCase = specialCaseMap + p->titleCaseDiff;
-        if (*specialCase == 1)
-            return specialCase[1];
+        return (*specialCase == 1) ? specialCase[1] : uc;
     }
     return uc + p->titleCaseDiff;
 }
@@ -1188,8 +1185,7 @@ static inline T toCaseFolded_helper(T uc)
     const QUnicodeTables::Properties *p = qGetProp(uc);
     if (p->caseFoldSpecial) {
         const ushort *specialCase = specialCaseMap + p->caseFoldDiff;
-        if (*specialCase == 1)
-            return specialCase[1];
+        return (*specialCase == 1) ? specialCase[1] : uc;
     }
     return uc + p->caseFoldDiff;
 }
index 142b7fb..18b816f 100644 (file)
@@ -129,6 +129,7 @@ void tst_QChar::toUpper()
     QVERIFY(QChar::toUpper((uint)0x10400) == 0x10400);
     QVERIFY(QChar::toUpper((uint)0x10428) == 0x10400);
 
+    QVERIFY(QChar::toUpper((uint)0xdf) == 0xdf); // german sharp s
 }
 
 void tst_QChar::toLower()
@@ -178,6 +179,7 @@ void tst_QChar::toTitle()
     QVERIFY(QChar::toTitleCase((uint)0x10400) == 0x10400);
     QVERIFY(QChar::toTitleCase((uint)0x10428) == 0x10400);
 
+    QVERIFY(QChar::toTitleCase((uint)0xdf) == 0xdf); // german sharp s
 }
 
 void tst_QChar::toCaseFolded()