Use ICU instead of iconv/windows codecs for the locale
authorLars Knoll <lars.knoll@nokia.com>
Wed, 25 Jul 2012 08:17:44 +0000 (10:17 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 31 Jul 2012 09:12:44 +0000 (11:12 +0200)
With ICU there's no need to use the windows locale or iconv
codecs anymore as locale codecs.

Change-Id: I50c94a97ed6acbf4c6f05b2a88593a57ebfa8342
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
src/corelib/codecs/codecs.pri
src/corelib/codecs/qicucodec.cpp
src/corelib/codecs/qicucodec_p.h
src/corelib/codecs/qtextcodec.cpp

index d049e52..0b40f79 100644 (file)
@@ -39,26 +39,26 @@ contains(QT_CONFIG,icu) {
         codecs/qsjiscodec.cpp \
         codecs/qeuckrcodec.cpp \
         codecs/qbig5codec.cpp
-}
 
-unix:!qnx:!mac:!ios:!linux-android-* {
-        contains(QT_CONFIG,iconv) {
-                HEADERS += codecs/qiconvcodec_p.h
-                SOURCES += codecs/qiconvcodec.cpp
-        } else:contains(QT_CONFIG,gnu-libiconv) {
-                HEADERS += codecs/qiconvcodec_p.h
-                SOURCES += codecs/qiconvcodec.cpp
-                DEFINES += GNU_LIBICONV
-                LIBS_PRIVATE *= -liconv
-        } else:contains(QT_CONFIG,sun-libiconv) {
-                HEADERS += codecs/qiconvcodec_p.h
-                SOURCES += codecs/qiconvcodec.cpp
-                DEFINES += GNU_LIBICONV
-        }
-} else {
-    DEFINES += QT_NO_ICONV
-}
-win32 {
-    SOURCES += codecs/qwindowscodec.cpp
-    HEADERS += codecs/qwindowscodec_p.h
+    unix:!qnx:!mac:!ios:!linux-android-* {
+            contains(QT_CONFIG,iconv) {
+                    HEADERS += codecs/qiconvcodec_p.h
+                    SOURCES += codecs/qiconvcodec.cpp
+            } else:contains(QT_CONFIG,gnu-libiconv) {
+                    HEADERS += codecs/qiconvcodec_p.h
+                    SOURCES += codecs/qiconvcodec.cpp
+                    DEFINES += GNU_LIBICONV
+                    LIBS_PRIVATE *= -liconv
+            } else:contains(QT_CONFIG,sun-libiconv) {
+                    HEADERS += codecs/qiconvcodec_p.h
+                    SOURCES += codecs/qiconvcodec.cpp
+                    DEFINES += GNU_LIBICONV
+            }
+    } else {
+        DEFINES += QT_NO_ICONV
+    }
+    win32 {
+        SOURCES += codecs/qwindowscodec.cpp
+        HEADERS += codecs/qwindowscodec_p.h
+    }
 }
index c91115b..56efcad 100644 (file)
@@ -372,7 +372,6 @@ QList<QByteArray> QIcuCodec::availableCodecs()
 
     // handled by Qt and not in ICU:
     codecs += "TSCII";
-    codecs += "System";
 
     return codecs;
 }
@@ -389,6 +388,21 @@ QList<int> QIcuCodec::availableMibs()
     return mibs;
 }
 
+QTextCodec *QIcuCodec::defaultCodec()
+{
+    QCoreGlobalData *globalData = QCoreGlobalData::instance();
+    if (!globalData)
+        return 0;
+    QTextCodec *c = globalData->codecForLocale.loadAcquire();
+    if (c)
+        return c;
+
+    const char *name = ucnv_getDefaultName();
+    c = codecForName(name);
+    globalData->codecForLocale.storeRelease(c);
+    return c;
+}
+
 static inline bool nameMatch(const QByteArray &a, const char *b)
 { return a == b; }
 
index 5f30eac..0a8ac7d 100644 (file)
@@ -67,6 +67,8 @@ public:
     static QList<QByteArray> availableCodecs();
     static QList<int> availableMibs();
 
+    static QTextCodec *defaultCodec();
+
     static QTextCodec *codecForName(const char *name);
     static QTextCodec *codecForMib(int mib);
 
index 3b0afdd..6fef779 100644 (file)
 #endif
 #include "private/qcoreglobaldata_p.h"
 
-#if !defined(QT_BOOTSTRAPPED)
-#if !defined(QT_NO_ICONV)
-#  include "qiconvcodec_p.h"
-#endif
-#ifdef Q_OS_WIN
-#  include "qwindowscodec_p.h"
-#endif
-#endif
-
 #include "qutfcodec_p.h"
 #include "qlatincodec_p.h"
 
 #if defined(QT_USE_ICU)
 #include "qicucodec_p.h"
 #else
+#if !defined(QT_NO_ICONV)
+#  include "qiconvcodec_p.h"
+#endif
+#ifdef Q_OS_WIN
+#  include "qwindowscodec_p.h"
+#endif
 #  include "qsimplecodec_p.h"
 #if !defined(QT_NO_BIG_CODECS)
 #  ifndef Q_OS_INTEGRITY
@@ -173,10 +170,12 @@ static QTextCodec *setupLocaleMapper()
     QCoreApplicationPrivate::initLocale();
 #endif
 
-#if defined(Q_OS_WIN) || defined(Q_OS_WINCE)
-    locale = QTextCodec::codecForName("System");
-#elif defined(Q_OS_MAC) || defined(Q_OS_IOS) || defined(Q_OS_LINUX_ANDROID) || defined(Q_OS_QNX)
+#if defined(Q_OS_MAC) || defined(Q_OS_IOS) || defined(Q_OS_LINUX_ANDROID) || defined(Q_OS_QNX)
     locale = QTextCodec::codecForName("UTF-8");
+#elif defined(QT_USE_ICU)
+    locale = QIcuCodec::defaultCodec();
+#elif defined(Q_OS_WIN) || defined(Q_OS_WINCE)
+    locale = QTextCodec::codecForName("System");
 #else
 
     // First try getting the codecs name from nl_langinfo and see
@@ -287,13 +286,13 @@ static void setup()
     (void)new QBig5Codec;
     (void)new QBig5hkscsCodec;
 #  endif // !QT_NO_BIG_CODECS && !Q_OS_INTEGRITY
-#endif // QT_USE_ICU
 #if !defined(QT_NO_ICONV)
     (void) new QIconvCodec;
 #endif
 #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
     (void) new QWindowsLocalCodec;
 #endif // Q_OS_WIN32
+#endif // QT_USE_ICU
 #endif // !QT_NO_CODECS && !QT_BOOTSTRAPPED
 
     (void)new QUtf16Codec;