QT_BEGIN_NAMESPACE
-extern bool qt_locale_initialized;
-
QIconvCodec::QIconvCodec()
: utf16Codec(0)
{
}
} else {
QThreadStorage<QIconvCodec::IconvState *> *ts = toUnicodeState();
- if (!qt_locale_initialized || !ts) {
+ if (!ts) {
// we're running after the Q_GLOBAL_STATIC has been deleted
// or before the QCoreApplication initialization
// bad programmer, no cookie for you
IconvState *temporaryState = 0;
QThreadStorage<QIconvCodec::IconvState *> *ts = fromUnicodeState();
- IconvState *&state = (qt_locale_initialized && ts) ? ts->localData() : temporaryState;
+ IconvState *&state = ts ? ts->localData() : temporaryState;
if (!state) {
iconv_t cd = QIconvCodec::createIconv_t(0, UTF16);
if (cd != reinterpret_cast<iconv_t>(-1)) {
#include "qfile.h"
#include "qstringlist.h"
#include "qvarlengtharray.h"
+#if !defined(QT_BOOTSTRAPPED)
+#include <private/qcoreapplication_p.h>
+#endif
#ifdef Q_OS_UNIX
# include "qiconvcodec_p.h"
#include <stdlib.h>
#include <ctype.h>
#include <locale.h>
-#if defined (_XOPEN_UNIX) && !defined(Q_OS_QNX) && \
- !defined(Q_OS_OSF) && !defined(Q_OS_LINUX_ANDROID)
+#if defined (_XOPEN_UNIX) && !defined(Q_OS_QNX) && !defined(Q_OS_OSF) && !defined(Q_OS_LINUX_ANDROID)
# include <langinfo.h>
#endif
static const char * const probably_koi8_rlocales[] = {
"ru", "ru_SU", "ru_RU", "russian", 0 };
-static QTextCodec * ru_RU_hack(const char * i) {
+static QTextCodec * ru_RU_hack(const char * i)
+{
QTextCodec * ru_RU_codec = 0;
-#if !defined(QT_NO_SETLOCALE)
QByteArray origlocale(setlocale(LC_CTYPE, i));
-#else
- QByteArray origlocale(i);
-#endif
// unicode koi8r latin5 name
// 0x044E 0xC0 0xEE CYRILLIC SMALL LETTER YU
// 0x042E 0xE0 0xCE CYRILLIC CAPITAL LETTER YU
qWarning("QTextCodec: Using KOI8-R, probe failed (%02x %02x %s)",
koi8r, latin5, i);
}
-#if !defined(QT_NO_SETLOCALE)
setlocale(LC_CTYPE, origlocale.constData());
-#endif
return ru_RU_codec;
}
-#endif
-
-#if !defined(Q_OS_WIN32) && !defined(Q_OS_WINCE)
static QTextCodec *checkForCodec(const QByteArray &name) {
QTextCodec *c = QTextCodec::codecForName(name);
if (!c) {
localeMapper = QTextCodec::codecForName("System");
#else
-#ifndef QT_NO_ICONV
- localeMapper = QTextCodec::codecForName("System");
+#if !defined(QT_BOOTSTRAPPED)
+ QCoreApplicationPrivate::initLocale();
#endif
-
-#if defined (_XOPEN_UNIX) && !defined(Q_OS_QNX) && \
- !defined(Q_OS_OSF) && !defined(Q_OS_LINUX_ANDROID)
+ // First try getting the codecs name from nl_langinfo and see
+ // if we have a builtin codec for it.
+ // Only fall back to using iconv if we can't find a builtin codec
+ // This is because the builtin utf8 codec is around 5 times faster
+ // then the using QIconvCodec
+
+#if defined (_XOPEN_UNIX) && !defined(Q_OS_QNX) && !defined(Q_OS_OSF) && !defined(Q_OS_LINUX_ANDROID)
+ char *charset = nl_langinfo(CODESET);
+ if (charset)
+ localeMapper = QTextCodec::codecForName(charset);
+#endif
+#if !defined(QT_NO_ICONV) && !defined(QT_BOOTSTRAPPED)
if (!localeMapper) {
- char *charset = nl_langinfo (CODESET);
- if (charset)
- localeMapper = QTextCodec::codecForName(charset);
+ // no builtin codec for the locale found, let's try using iconv
+ (void) new QIconvCodec();
+ localeMapper = QTextCodec::codecForName("System");
}
#endif
// First part is getting that locale name. First try setlocale() which
// definitely knows it, but since we cannot fully trust it, get ready
// to fall back to environment variables.
-#if !defined(QT_NO_SETLOCALE)
const QByteArray ctype = setlocale(LC_CTYPE, 0);
-#else
- const QByteArray ctype;
-#endif
// Get the first nonempty value from $LC_ALL, $LC_CTYPE, and $LANG
// environment variables.
(void)new QLatin1Codec;
(void)new QUtf8Codec;
-#if !defined(Q_OS_INTEGRITY)
-#if defined(Q_OS_UNIX) && !defined(QT_NO_ICONV) && !defined(QT_BOOTSTRAPPED)
- // QIconvCodec depends on the UTF-16 codec, so it needs to be created last
- (void) new QIconvCodec();
-#endif
-#endif
-
if (!localeMapper)
setupLocaleMapper();
}
Returns a pointer to the codec most suitable for this locale.
On Windows, the codec will be based on a system locale. On Unix
- systems, starting with Qt 4.2, the codec will be using the \e
- iconv library. Note that in both cases the codec's name will be
- "System".
+ systems, the codec will might fall back to using the \e iconv
+ library if no builtin codec for the locale can be found.
+
+ Note that in these cases the codec's name will be "System".
*/
QTextCodec* QTextCodec::codecForLocale()
// app closing down if true
bool QCoreApplicationPrivate::is_app_closing = false;
// initialized in qcoreapplication and in qtextstream autotest when setlocale is called.
-Q_CORE_EXPORT bool qt_locale_initialized = false;
+static bool qt_locale_initialized = false;
Q_CORE_EXPORT uint qGlobalPostedEventsCount()
{
return QCoreApplication::instance()->d_func()->appName();
}
+void QCoreApplicationPrivate::initLocale()
+{
+ if (qt_locale_initialized)
+ return;
+ qt_locale_initialized = true;
+#ifdef Q_OS_UNIX
+ setlocale(LC_ALL, "");
+#endif
+}
+
+
/*!
\class QCoreApplication
\brief The QCoreApplication class provides an event loop for console Qt
{
Q_D(QCoreApplication);
-#ifdef Q_OS_UNIX
- setlocale(LC_ALL, ""); // use correct char set mapping
- qt_locale_initialized = true;
-#endif
+ QCoreApplicationPrivate::initLocale();
Q_ASSERT_X(!self, "QCoreApplication", "there should be only one application object");
QCoreApplication::self = this;