verify codec is provided by ICU codec before attempting to create it

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
Ivailo Monev 2019-11-23 18:35:30 +00:00
parent e9622b5dd4
commit 7a7f5173cd

View file

@ -105,6 +105,8 @@ static bool nameMatch(const QByteArray &name, const QByteArray &test)
return (*h == '\0');
}
static QList<QByteArray> icucodecs;
static QTextCodec *createForName(const QByteArray &name)
{
#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_TEXTCODECPLUGIN)
@ -123,7 +125,17 @@ static QTextCodec *createForName(const QByteArray &name)
Q_UNUSED(name);
#endif
return new QIcuCodec(name.constData());
if (icucodecs.isEmpty()) {
icucodecs = QIcuCodec::availableCodecs();
}
foreach(const QByteArray codec, icucodecs) {
if (nameMatch(name, codec)) {
return new QIcuCodec(name.constData());
}
}
return Q_NULLPTR;
}
static QTextCodec *createForMib(int mib)