diff --git a/src/common/textcodec.cpp b/src/common/textcodec.cpp index b76c4fe5..c86a9e44 100644 --- a/src/common/textcodec.cpp +++ b/src/common/textcodec.cpp @@ -1,6 +1,70 @@ -#include #include "textcodec.h" +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + +#include + +TextCodec::TextCodec() +{ + _codec = QTextCodec::codecForName("Windows-1252"); +} + +TextCodec::TextCodec(int codepage) +{ + switch (codepage) { + case 65001: + _codec = 0; + break; + case 932: + _codec = QTextCodec::codecForName("Shift-JIS"); + break; + case 936: + _codec = QTextCodec::codecForName("GB18030"); + break; + case 949: + _codec = QTextCodec::codecForName("EUC-KR"); + break; + case 950: + _codec = QTextCodec::codecForName("Big5"); + break; + case 1250: + _codec = QTextCodec::codecForName("Windows-1250"); + break; + case 1251: + _codec = QTextCodec::codecForName("Windows-1251"); + break; + case 1253: + _codec = QTextCodec::codecForName("Windows-1253"); + break; + case 1254: + _codec = QTextCodec::codecForName("Windows-1254"); + break; + case 1255: + _codec = QTextCodec::codecForName("Windows-1255"); + break; + case 1256: + _codec = QTextCodec::codecForName("Windows-1256"); + break; + case 1257: + _codec = QTextCodec::codecForName("Windows-1257"); + break; + case 1258: + _codec = QTextCodec::codecForName("Windows-1258"); + break; + default: + _codec = QTextCodec::codecForName("Windows-1252"); + } +} + +QString TextCodec::toString(const QByteArray &ba) const +{ + return _codec ? _codec->toUnicode(ba) : QString::fromUtf8(ba); +} + +#else // QT6 + +#include + static const char32_t cp1250[] = { 0x20AC, 0x0000, 0x201A, 0x0000, 0x201E, 0x2026, 0x2020, 0x2021, 0x0000, 0x2030, 0x0160, 0x2039, 0x015A, 0x0164, 0x017D, 0x0179, @@ -192,10 +256,7 @@ TextCodec::TextCodec(int codepage) QString TextCodec::toString(const QByteArray &ba) const { - if (_table) - return from8bCp(ba); - else - return QString::fromUtf8(ba); + return _table ? from8bCp(ba) : QString::fromUtf8(ba); } QString TextCodec::from8bCp(const QByteArray &ba) const @@ -212,3 +273,4 @@ QString TextCodec::from8bCp(const QByteArray &ba) const return QString::fromUcs4(ucs4.constData(), ucs4.size()); } +#endif // QT6 diff --git a/src/common/textcodec.h b/src/common/textcodec.h index b8d4f99d..7e5307fe 100644 --- a/src/common/textcodec.h +++ b/src/common/textcodec.h @@ -3,6 +3,8 @@ #include +class QTextCodec; + class TextCodec { public: @@ -12,9 +14,12 @@ public: QString toString(const QByteArray &ba) const; private: +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + QTextCodec *_codec; +#else // QT6 QString from8bCp(const QByteArray &ba) const; - const char32_t *_table; +#endif // QT6 }; #endif // TEXTCODEC_H