コード例 #1
0
ファイル: qtextcodec.cpp プロジェクト: 2gis/2gisqt5android
/*!
    \threadsafe
    Returns the QTextCodec which matches the
    \l{QTextCodec::mibEnum()}{MIBenum} \a mib.
*/
QTextCodec* QTextCodec::codecForMib(int mib)
{
    QMutexLocker locker(textCodecsMutex());

    QCoreGlobalData *globalData = QCoreGlobalData::instance();
    if (!globalData)
        return 0;
    if (globalData->allCodecs.isEmpty())
        setup();

    QByteArray key = "MIB: " + QByteArray::number(mib);

    QTextCodecCache *cache = &globalData->codecCache;
    QTextCodec *codec;
    if (cache) {
        codec = cache->value(key);
        if (codec)
            return codec;
    }

    for (TextCodecListConstIt it = globalData->allCodecs.constBegin(), cend = globalData->allCodecs.constEnd(); it != cend; ++it) {
        QTextCodec *cursor = *it;
        if (cursor->mibEnum() == mib) {
            if (cache)
                cache->insert(key, cursor);
            return cursor;
        }
    }

#ifdef QT_USE_ICU
    return QIcuCodec::codecForMibUnlocked(mib);
#else
    return 0;
#endif
}
コード例 #2
0
ファイル: qtextcodec.cpp プロジェクト: wpbest/copperspice
/*!
    Returns the list of all available codecs, by name. Call
    QTextCodec::codecForName() to obtain the QTextCodec for the name.

    The list may contain many mentions of the same codec
    if the codec has aliases.

    \sa availableMibs(), name(), aliases()
*/
QList<QByteArray> QTextCodec::availableCodecs()
{
    QMutexLocker locker(textCodecsMutex());
    setup();

    QList<QByteArray> codecs;

    if (!validCodecs())
        return codecs;

    for (int i = 0; i < all->size(); ++i) {
        codecs += all->at(i)->name();
        codecs += all->at(i)->aliases();
    }

    locker.unlock();


#if ! defined(QT_NO_TEXTCODECPLUGIN)
    QFactoryLoader *l = loader();
    QStringList keys = l->keys();
    for (int i = 0; i < keys.size(); ++i) {
        if (!keys.at(i).startsWith(QLatin1String("MIB: "))) {
            QByteArray name = keys.at(i).toLatin1();
            if (!codecs.contains(name))
                codecs += name;
        }
    }
#endif

    return codecs;
}
コード例 #3
0
ファイル: qtextcodec.cpp プロジェクト: wpbest/copperspice
/*!
    Returns the list of MIBs for all available codecs. Call
    QTextCodec::codecForMib() to obtain the QTextCodec for the MIB.

    \sa availableCodecs(), mibEnum()
*/
QList<int> QTextCodec::availableMibs()
{
    QMutexLocker locker(textCodecsMutex());
    setup();

    QList<int> codecs;

    if (!validCodecs())
        return codecs;

    for (int i = 0; i < all->size(); ++i)
        codecs += all->at(i)->mibEnum();

    locker.unlock();


#if ! defined(QT_NO_TEXTCODECPLUGIN)
    QFactoryLoader *l = loader();
    QStringList keys = l->keys();
    for (int i = 0; i < keys.size(); ++i) {
        if (keys.at(i).startsWith(QLatin1String("MIB: "))) {
            int mib = keys.at(i).mid(5).toInt();
            if (!codecs.contains(mib))
                codecs += mib;
        }
    }
#endif

    return codecs;
}
コード例 #4
0
ファイル: qtextcodec.cpp プロジェクト: wpbest/copperspice
/*!
    Constructs a QTextCodec, and gives it the highest precedence. The
    QTextCodec should always be constructed on the heap (i.e. with \c
    new). Qt takes ownership and will delete it when the application
    terminates.
*/
QTextCodec::QTextCodec()
{
    QMutexLocker locker(textCodecsMutex());

    setup();
    all->prepend(this);
}
コード例 #5
0
ファイル: qtextcodec.cpp プロジェクト: wpbest/copperspice
/*!
    Set the codec to \a c; this will be returned by
    codecForLocale(). If \a c is a null pointer, the codec is reset to
    the default.

    This might be needed for some applications that want to use their
    own mechanism for setting the locale.

    \sa codecForLocale()
*/
void QTextCodec::setCodecForLocale(QTextCodec *c)
{
    QMutexLocker locker(textCodecsMutex());

    localeMapper = c;
    if (!localeMapper)
        setupLocaleMapper();
}
コード例 #6
0
ファイル: qtextcodec.cpp プロジェクト: 2gis/2gisqt5android
/*!
    Constructs a QTextCodec, and gives it the highest precedence. The
    QTextCodec should always be constructed on the heap (i.e. with \c
    new). Qt takes ownership and will delete it when the application
    terminates.
*/
QTextCodec::QTextCodec()
{
    QMutexLocker locker(textCodecsMutex());

    QCoreGlobalData *globalInstance = QCoreGlobalData::instance();
    if (globalInstance->allCodecs.isEmpty())
        setup();

    globalInstance->allCodecs.prepend(this);
}
コード例 #7
0
ファイル: qtextcodec.cpp プロジェクト: 2gis/2gisqt5android
QTextCodec* QTextCodec::codecForLocale()
{
    QCoreGlobalData *globalData = QCoreGlobalData::instance();
    if (!globalData)
        return 0;

    QTextCodec *codec = globalData->codecForLocale.loadAcquire();
    if (!codec) {
#ifdef QT_USE_ICU
        textCodecsMutex()->lock();
        codec = QIcuCodec::defaultCodecUnlocked();
        textCodecsMutex()->unlock();
#else
        // setupLocaleMapper locks as necessary
        codec = setupLocaleMapper();
#endif
    }

    return codec;
}
コード例 #8
0
ファイル: qtextcodec.cpp プロジェクト: wpbest/copperspice
QTextCodec* QTextCodec::codecForLocale()
{
    if (!validCodecs())
        return 0;

    if (localeMapper)
        return localeMapper;

    QMutexLocker locker(textCodecsMutex());
    setup();

    return localeMapper;
}
コード例 #9
0
ファイル: qtextcodec.cpp プロジェクト: wpbest/copperspice
/*!
    \nonreentrant

    Destroys the QTextCodec. Note that you should not delete codecs
    yourself: once created they become Qt's responsibility.
*/
QTextCodec::~QTextCodec()
{
#ifdef Q_DEBUG_TEXTCODEC
    if (!destroying_is_ok)
        qWarning("QTextCodec::~QTextCodec: Called by application");
#endif
    if (all) {
        QMutexLocker locker(textCodecsMutex());

        all->removeAll(this);
        QTextCodecCache *cache = qTextCodecCache();
        if (cache)
            cache->clear();
    }
}
コード例 #10
0
ファイル: qtextcodec.cpp プロジェクト: 2gis/2gisqt5android
/*!
    \threadsafe
    Returns the list of MIBs for all available codecs. Call
    QTextCodec::codecForMib() to obtain the QTextCodec for the MIB.

    \sa availableCodecs(), mibEnum()
*/
QList<int> QTextCodec::availableMibs()
{
#ifdef QT_USE_ICU
    return QIcuCodec::availableMibs();
#else
    QMutexLocker locker(textCodecsMutex());

    QCoreGlobalData *globalData = QCoreGlobalData::instance();
    if (globalData->allCodecs.isEmpty())
        setup();

    QList<int> codecs;

    for (TextCodecListConstIt it = globalData->allCodecs.constBegin(), cend = globalData->allCodecs.constEnd(); it != cend; ++it)
        codecs += (*it)->mibEnum();

    return codecs;
#endif
}
コード例 #11
0
ファイル: qtextcodec.cpp プロジェクト: 2gis/2gisqt5android
/*!
    \threadsafe
    Searches all installed QTextCodec objects and returns the one
    which best matches \a name; the match is case-insensitive. Returns
    0 if no codec matching the name \a name could be found.
*/
QTextCodec *QTextCodec::codecForName(const QByteArray &name)
{
    if (name.isEmpty())
        return 0;

    QMutexLocker locker(textCodecsMutex());

    QCoreGlobalData *globalData = QCoreGlobalData::instance();
    if (!globalData)
        return 0;
    setup();

#ifndef QT_USE_ICU
    QTextCodecCache *cache = &globalData->codecCache;
    QTextCodec *codec;
    if (cache) {
        codec = cache->value(name);
        if (codec)
            return codec;
    }

    for (TextCodecListConstIt it = globalData->allCodecs.constBegin(), cend = globalData->allCodecs.constEnd(); it != cend; ++it) {
        QTextCodec *cursor = *it;
        if (qTextCodecNameMatch(cursor->name(), name)) {
            if (cache)
                cache->insert(name, cursor);
            return cursor;
        }
        QList<QByteArray> aliases = cursor->aliases();
        for (ByteArrayListConstIt ait = aliases.constBegin(), acend = aliases.constEnd(); ait != acend; ++ait) {
            if (qTextCodecNameMatch(*ait, name)) {
                if (cache)
                    cache->insert(name, cursor);
                return cursor;
            }
        }
    }

    return 0;
#else
    return QIcuCodec::codecForNameUnlocked(name);
#endif
}
コード例 #12
0
ファイル: qtextcodec.cpp プロジェクト: cedrus/qt
/*!
    \threadsafe
    Returns the list of MIBs for all available codecs. Call
    QTextCodec::codecForMib() to obtain the QTextCodec for the MIB.

    \sa availableCodecs(), mibEnum()
*/
QList<int> QTextCodec::availableMibs()
{
#ifdef QT_USE_ICU
    return QIcuCodec::availableMibs();
#else
    QMutexLocker locker(textCodecsMutex());

    QCoreGlobalData *globalData = QCoreGlobalData::instance();
    if (globalData->allCodecs.isEmpty())
        setup();

    QList<int> codecs;

    for (int i = 0; i < globalData->allCodecs.size(); ++i)
        codecs += globalData->allCodecs.at(i)->mibEnum();

    return codecs;
#endif
}
コード例 #13
0
ファイル: qtextcodec.cpp プロジェクト: cedrus/qt
/*!
    \threadsafe
    Searches all installed QTextCodec objects and returns the one
    which best matches \a name; the match is case-insensitive. Returns
    0 if no codec matching the name \a name could be found.
*/
QTextCodec *QTextCodec::codecForName(const QByteArray &name)
{
    if (name.isEmpty())
        return 0;

    QMutexLocker locker(textCodecsMutex());

    QCoreGlobalData *globalData = QCoreGlobalData::instance();
    if (!globalData)
        return 0;
        setup();

#ifndef QT_USE_ICU
    QTextCodecCache *cache = &globalData->codecCache;
    QTextCodec *codec;
    if (cache) {
        codec = cache->value(name);
        if (codec)
            return codec;
    }

    for (int i = 0; i < globalData->allCodecs.size(); ++i) {
        QTextCodec *cursor = globalData->allCodecs.at(i);
        if (qTextCodecNameMatch(cursor->name(), name)) {
            if (cache)
                cache->insert(name, cursor);
            return cursor;
        }
        QList<QByteArray> aliases = cursor->aliases();
        for (int y = 0; y < aliases.size(); ++y)
            if (qTextCodecNameMatch(aliases.at(y), name)) {
                if (cache)
                    cache->insert(name, cursor);
                return cursor;
            }
    }

    return 0;
#else
    return QIcuCodec::codecForNameUnlocked(name);
#endif
}
コード例 #14
0
ファイル: qtextcodec.cpp プロジェクト: 2gis/2gisqt5android
/*!
    \threadsafe
    Returns the list of all available codecs, by name. Call
    QTextCodec::codecForName() to obtain the QTextCodec for the name.

    The list may contain many mentions of the same codec
    if the codec has aliases.

    \sa availableMibs(), name(), aliases()
*/
QList<QByteArray> QTextCodec::availableCodecs()
{
    QMutexLocker locker(textCodecsMutex());

    QCoreGlobalData *globalData = QCoreGlobalData::instance();
    if (globalData->allCodecs.isEmpty())
        setup();

    QList<QByteArray> codecs;

    for (TextCodecListConstIt it = globalData->allCodecs.constBegin(), cend = globalData->allCodecs.constEnd(); it != cend; ++it) {
        codecs += (*it)->name();
        codecs += (*it)->aliases();
    }

#ifdef QT_USE_ICU
    codecs += QIcuCodec::availableCodecs();
#endif

    return codecs;
}
コード例 #15
0
ファイル: qtextcodec.cpp プロジェクト: cedrus/qt
/*!
    \threadsafe
    Returns the list of all available codecs, by name. Call
    QTextCodec::codecForName() to obtain the QTextCodec for the name.

    The list may contain many mentions of the same codec
    if the codec has aliases.

    \sa availableMibs(), name(), aliases()
*/
QList<QByteArray> QTextCodec::availableCodecs()
{
    QMutexLocker locker(textCodecsMutex());

    QCoreGlobalData *globalData = QCoreGlobalData::instance();
    if (globalData->allCodecs.isEmpty())
        setup();

    QList<QByteArray> codecs;

    for (int i = 0; i < globalData->allCodecs.size(); ++i) {
        codecs += globalData->allCodecs.at(i)->name();
        codecs += globalData->allCodecs.at(i)->aliases();
    }

#ifdef QT_USE_ICU
    codecs += QIcuCodec::availableCodecs();
#endif

    return codecs;
}
コード例 #16
0
ファイル: qtextcodec.cpp プロジェクト: wpbest/copperspice
/*!
    Searches all installed QTextCodec objects and returns the one
    which best matches \a name; the match is case-insensitive. Returns
    0 if no codec matching the name \a name could be found.
*/
QTextCodec *QTextCodec::codecForName(const QByteArray &name)
{
    if (name.isEmpty())
        return 0;

    QMutexLocker locker(textCodecsMutex());
    setup();

    if (!validCodecs())
        return 0;

    QTextCodecCache *cache = qTextCodecCache();
    QTextCodec *codec;
    if (cache) {
        codec = cache->value(name);
        if (codec)
            return codec;
    }

    for (int i = 0; i < all->size(); ++i) {
        QTextCodec *cursor = all->at(i);
        if (nameMatch(cursor->name(), name)) {
            if (cache)
                cache->insert(name, cursor);
            return cursor;
        }
        QList<QByteArray> aliases = cursor->aliases();
        for (int y = 0; y < aliases.size(); ++y)
            if (nameMatch(aliases.at(y), name)) {
                if (cache)
                    cache->insert(name, cursor);
                return cursor;
            }
    }

    codec = createForName(name);
    if (codec && cache)
        cache->insert(name, codec);
    return codec;
}
コード例 #17
0
ファイル: qtextcodec.cpp プロジェクト: wpbest/copperspice
/*!
    Returns the QTextCodec which matches the \link
    QTextCodec::mibEnum() MIBenum\endlink \a mib.
*/
QTextCodec* QTextCodec::codecForMib(int mib)
{
    QMutexLocker locker(textCodecsMutex());

    setup();

    if (!validCodecs())
        return 0;

    QByteArray key = "MIB: " + QByteArray::number(mib);
    QTextCodecCache *cache = qTextCodecCache();
    QTextCodec *codec;
    if (cache) {
        codec = cache->value(key);
        if (codec)
            return codec;
    }

    QList<QTextCodec*>::ConstIterator i;
    for (int i = 0; i < all->size(); ++i) {
        QTextCodec *cursor = all->at(i);
        if (cursor->mibEnum() == mib) {
            if (cache)
                cache->insert(key, cursor);
            return cursor;
        }
    }

    codec = createForMib(mib);

    // Qt 3 used 1000 (mib for UCS2) as its identifier for the utf16 codec. Map
    // this correctly for compatibility.
    if (!codec && mib == 1000)
        return codecForMib(1015);

    if (codec && cache)
        cache->insert(key, codec);
    return codec;
}
コード例 #18
0
ファイル: qtextcodec.cpp プロジェクト: cedrus/qt
/*!
    \threadsafe
    Returns the QTextCodec which matches the
    \l{QTextCodec::mibEnum()}{MIBenum} \a mib.
*/
QTextCodec* QTextCodec::codecForMib(int mib)
{
    QMutexLocker locker(textCodecsMutex());

    QCoreGlobalData *globalData = QCoreGlobalData::instance();
    if (!globalData)
        return 0;
    if (globalData->allCodecs.isEmpty())
        setup();

    QByteArray key = "MIB: " + QByteArray::number(mib);

    QTextCodecCache *cache = &globalData->codecCache;
    QTextCodec *codec;
    if (cache) {
        codec = cache->value(key);
        if (codec)
            return codec;
    }

    QList<QTextCodec*>::ConstIterator i;
    for (int i = 0; i < globalData->allCodecs.size(); ++i) {
        QTextCodec *cursor = globalData->allCodecs.at(i);
        if (cursor->mibEnum() == mib) {
            if (cache)
                cache->insert(key, cursor);
            return cursor;
        }
    }

#ifdef QT_USE_ICU
    return QIcuCodec::codecForMibUnlocked(mib);
#else
    return 0;
#endif
}
コード例 #19
0
ファイル: qtextcodec.cpp プロジェクト: 2gis/2gisqt5android
// \threadsafe
// this returns the codec the method sets up as locale codec to
// avoid a race condition in codecForLocale() when
// setCodecForLocale(0) is called at the same time.
static QTextCodec *setupLocaleMapper()
{
    QCoreGlobalData *globalData = QCoreGlobalData::instance();

    QTextCodec *locale = 0;

    {
        QMutexLocker locker(textCodecsMutex());
        if (globalData->allCodecs.isEmpty())
            setup();
    }

#if !defined(QT_BOOTSTRAPPED)
    QCoreApplicationPrivate::initLocale();
#endif

#if defined(QT_LOCALE_IS_UTF8)
    locale = QTextCodec::codecForName("UTF-8");
#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
    // 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_OSF)
    char *charset = nl_langinfo(CODESET);
    if (charset)
        locale = QTextCodec::codecForName(charset);
#endif
#if !defined(QT_NO_ICONV) && !defined(QT_BOOTSTRAPPED)
    if (!locale) {
        // no builtin codec for the locale found, let's try using iconv
        (void) new QIconvCodec();
        locale = QTextCodec::codecForName("System");
    }
#endif

    if (!locale) {
        // Very poorly defined and followed standards causes lots of
        // code to try to get all the cases... This logic is
        // duplicated in QIconvCodec, so if you change it here, change
        // it there too.

        // Try to determine locale codeset from locale name assigned to
        // LC_CTYPE category.

        // 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.
        const QByteArray ctype = setlocale(LC_CTYPE, 0);

        // Get the first nonempty value from $LC_ALL, $LC_CTYPE, and $LANG
        // environment variables.
        QByteArray lang = qgetenv("LC_ALL");
        if (lang.isEmpty() || lang == "C") {
            lang = qgetenv("LC_CTYPE");
        }
        if (lang.isEmpty() || lang == "C") {
            lang = qgetenv("LANG");
        }

        // Now try these in order:
        // 1. CODESET from ctype if it contains a .CODESET part (e.g. en_US.ISO8859-15)
        // 2. CODESET from lang if it contains a .CODESET part
        // 3. ctype (maybe the locale is named "ISO-8859-1" or something)
        // 4. locale (ditto)
        // 5. check for "@euro"
        // 6. guess locale from ctype unless ctype is "C"
        // 7. guess locale from lang

        // 1. CODESET from ctype if it contains a .CODESET part (e.g. en_US.ISO8859-15)
        int indexOfDot = ctype.indexOf('.');
        if (indexOfDot != -1)
            locale = checkForCodec( ctype.mid(indexOfDot + 1) );

        // 2. CODESET from lang if it contains a .CODESET part
        if (!locale) {
            indexOfDot = lang.indexOf('.');
            if (indexOfDot != -1)
                locale = checkForCodec( lang.mid(indexOfDot + 1) );
        }

        // 3. ctype (maybe the locale is named "ISO-8859-1" or something)
        if (!locale && !ctype.isEmpty() && ctype != "C")
            locale = checkForCodec(ctype);

        // 4. locale (ditto)
        if (!locale && !lang.isEmpty())
            locale = checkForCodec(lang);

        // 5. "@euro"
        if ((!locale && ctype.contains("@euro")) || lang.contains("@euro"))
            locale = checkForCodec("ISO 8859-15");
    }

#endif
    // If everything failed, we default to 8859-1
    if (!locale)
        locale = QTextCodec::codecForName("ISO 8859-1");
    globalData->codecForLocale.storeRelease(locale);
    return locale;
}
コード例 #20
0
ファイル: qtextcodec.cpp プロジェクト: 2gis/2gisqt5android
QMutex *qTextCodecsMutex() { return textCodecsMutex(); }
コード例 #21
0
ファイル: qtextcodec.cpp プロジェクト: cedrus/qt
/*!
    Constructs a QTextCodec, and gives it the highest precedence. The
    QTextCodec should always be constructed on the heap (i.e. with \c
    new). Qt takes ownership and will delete it when the application
    terminates.
*/
QTextCodec::QTextCodec()
{
    QMutexLocker locker(textCodecsMutex());

    QCoreGlobalData::instance()->allCodecs.prepend(this);
}