From b05e7b15fe52214058582983c60957ee0e6270d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Fri, 19 Jan 2024 09:56:56 +0100 Subject: [PATCH] Use ISO-8859-1 as the fallback encoding rather than UTF-8 --- src/common/textcodec.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/common/textcodec.cpp b/src/common/textcodec.cpp index 46f9709d..fd64e3aa 100644 --- a/src/common/textcodec.cpp +++ b/src/common/textcodec.cpp @@ -6,7 +6,7 @@ static QTextCodec *codec(int mib) { QTextCodec *c = QTextCodec::codecForMib(mib); if (!c) - qWarning("MIB-%d: No such QTextCodec, using UTF-8", mib); + qWarning("MIB-%d: No such QTextCodec, using ISO-8859-1", mib); return c; } @@ -61,17 +61,17 @@ TextCodec::TextCodec(int codepage) _codec = codec(2258); break; case 65001: - _codec = 0; + _codec = codec(106); break; default: - qWarning("%d: Unknown codepage, using UTF-8", codepage); + qWarning("%d: Unknown codepage, using ISO-8859-1", codepage); _codec = 0; } } QString TextCodec::toString(const QByteArray &ba) { - return _codec ? _codec->toUnicode(ba) : QString::fromUtf8(ba); + return _codec ? _codec->toUnicode(ba) : QString::fromLatin1(ba); } #else // QT 6.5 @@ -82,17 +82,19 @@ TextCodec::TextCodec() TextCodec::TextCodec(int codepage) { - if (codepage != 65001) { + if (codepage == 65001) + _decoder = QStringDecoder(QStringDecoder::Utf8); + else { QByteArray cp(QByteArray("CP") + QByteArray::number(codepage)); _decoder = QStringDecoder(cp.constData()); if (!_decoder.isValid()) - qWarning("%d: Unknown codepage, using UTF-8", codepage); + qWarning("%d: Unknown codepage, using ISO-8859-1", codepage); } } QString TextCodec::toString(const QByteArray &ba) { - return _decoder.isValid() ? _decoder.decode(ba) : QString::fromUtf8(ba); + return _decoder.isValid() ? _decoder.decode(ba) : QString::fromLatin1(ba); } #endif // QT 6.5