2021-10-25 10:30:09 +02:00
|
|
|
#include <QTextCodec>
|
2021-10-27 20:29:12 +02:00
|
|
|
#include "textcodec.h"
|
2021-10-25 10:30:09 +02:00
|
|
|
|
2023-12-22 09:32:47 +01:00
|
|
|
static QTextCodec *codec(int mib)
|
2021-10-25 10:30:09 +02:00
|
|
|
{
|
2023-12-22 09:32:47 +01:00
|
|
|
QTextCodec *c = QTextCodec::codecForMib(mib);
|
|
|
|
if (!c)
|
|
|
|
qWarning("MIB-%d: No such QTextCodec, using UTF-8", mib);
|
2023-12-21 01:31:44 +01:00
|
|
|
|
2023-12-22 09:32:47 +01:00
|
|
|
return c;
|
2021-10-25 10:30:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TextCodec::TextCodec(int codepage)
|
|
|
|
{
|
2023-12-22 09:32:47 +01:00
|
|
|
switch (codepage) {
|
|
|
|
case 874:
|
|
|
|
_codec = codec(2109);
|
|
|
|
break;
|
|
|
|
case 932:
|
|
|
|
_codec = codec(17);
|
|
|
|
break;
|
|
|
|
case 936:
|
|
|
|
_codec = codec(114);
|
|
|
|
break;
|
|
|
|
case 949:
|
|
|
|
_codec = codec(38);
|
|
|
|
break;
|
|
|
|
case 950:
|
|
|
|
_codec = codec(2026);
|
|
|
|
break;
|
|
|
|
case 1250:
|
|
|
|
_codec = codec(2250);
|
|
|
|
break;
|
|
|
|
case 1251:
|
|
|
|
_codec = codec(2251);
|
|
|
|
break;
|
|
|
|
case 1252:
|
|
|
|
_codec = codec(2252);
|
|
|
|
break;
|
|
|
|
case 1253:
|
|
|
|
_codec = codec(2253);
|
|
|
|
break;
|
|
|
|
case 1254:
|
|
|
|
_codec = codec(2254);
|
|
|
|
break;
|
|
|
|
case 1255:
|
|
|
|
_codec = codec(2255);
|
|
|
|
break;
|
|
|
|
case 1256:
|
|
|
|
_codec = codec(2256);
|
|
|
|
break;
|
|
|
|
case 1257:
|
|
|
|
_codec = codec(2257);
|
|
|
|
break;
|
|
|
|
case 1258:
|
|
|
|
_codec = codec(2258);
|
|
|
|
break;
|
|
|
|
case 65001:
|
|
|
|
_codec = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qWarning("%d: Unknown codepage, using UTF-8", codepage);
|
|
|
|
_codec = 0;
|
|
|
|
}
|
2021-10-25 10:30:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString TextCodec::toString(const QByteArray &ba) const
|
|
|
|
{
|
|
|
|
return _codec ? _codec->toUnicode(ba) : QString::fromUtf8(ba);
|
|
|
|
}
|