QTextCodec *QIsciiCodec::create(const char *name) { for (int i = 0; i < 9; ++i) { if (qTextCodecNameMatch(name, codecs[i].name)) return new QIsciiCodec(i); } return 0; }
int QIcuCodec::mibEnum() const { for (int i = 0; i < mibToNameSize; ++i) { if (qTextCodecNameMatch(m_name, (mibToNameTable + mibToName[i].index))) return mibToName[i].mib; } return 0; }
/*! \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 }
/*! \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 }
QTextCodec *QIcuCodec::codecForNameUnlocked(const char *name) { // backwards compatibility with Qt 4.x if (!qstrcmp(name, "CP949")) name = "windows-949"; // these are broken data in ICU 4.4, and can't be resolved even though they are aliases to tis-620 if (!qstrcmp(name, "windows-874-2000") || !qstrcmp(name, "windows-874") || !qstrcmp(name, "MS874") || !qstrcmp(name, "x-windows-874") || !qstrcmp(name, "ISO 8859-11")) name = "TIS-620"; UErrorCode error = U_ZERO_ERROR; // MIME gives better default names const char *standardName = ucnv_getStandardName(name, "MIME", &error); if (U_FAILURE(error) || !standardName) { error = U_ZERO_ERROR; standardName = ucnv_getStandardName(name, "IANA", &error); } bool qt_only = false; if (U_FAILURE(error) || !standardName) { standardName = name; qt_only = true; } else { // correct some issues where the ICU data set contains duplicated entries. // Where this happens it's because one data set is a subset of another. We // always use the larger data set. if (qstrcmp(standardName, "GB2312") == 0 || qstrcmp(standardName, "GB_2312-80") == 0) standardName = "GBK"; else if (qstrcmp(standardName, "KSC_5601") == 0 || qstrcmp(standardName, "EUC-KR") == 0 || qstrcmp(standardName, "cp1363") == 0) standardName = "windows-949"; } QCoreGlobalData *globalData = QCoreGlobalData::instance(); QTextCodecCache *cache = &globalData->codecCache; QTextCodec *codec; if (cache) { codec = cache->value(standardName); if (codec) return codec; } for (int i = 0; i < globalData->allCodecs.size(); ++i) { QTextCodec *cursor = globalData->allCodecs.at(i); if (qTextCodecNameMatch(cursor->name(), standardName)) { if (cache) cache->insert(standardName, cursor); return cursor; } QList<QByteArray> aliases = cursor->aliases(); for (int y = 0; y < aliases.size(); ++y) if (qTextCodecNameMatch(aliases.at(y), standardName)) { if (cache) cache->insert(standardName, cursor); return cursor; } } QTextCodec *c = loadQtCodec(standardName); if (c) return c; if (qt_only) return 0; // check whether there is really a converter for the name available. UConverter *conv = ucnv_open(standardName, &error); if (!conv) { qDebug() << "codecForName: ucnv_open failed" << standardName << u_errorName(error); return 0; } //qDebug() << "QIcuCodec: Standard name for " << name << "is" << standardName; ucnv_close(conv); c = new QIcuCodec(standardName); if (cache) cache->insert(standardName, c); return c; }