15#ifdef BT_CP1252_USE_QT
16#include <QStringDecoder>
17#include <QStringEncoder>
21#include <unicode/ucnv.h>
29#ifdef BT_CP1252_USE_QT
31QString
toUnicode(QByteArray
const & data,
bool & error) {
32 QStringDecoder decoder(
"Windows-1252", QStringDecoder::Flag::Stateless);
34 QString result = decoder(data);
35 error = decoder.hasError();
39QByteArray
fromUnicode(QString
const & str,
bool & error) {
40 QStringEncoder encoder(
"Windows-1252", QStringEncoder::Flag::Stateless);
42 QByteArray result = encoder(str);
43 error = encoder.hasError();
57 ::UErrorCode err = ::U_ZERO_ERROR;
58 auto const r = ::ucnv_open(
"cp1252", &err);
60 qFatal() <<
"Failed to initialize CP1252 converter:"
61 << ::u_errorName(err);
74 QString
toUnicode(QByteArray
const & data,
bool & error) {
75 ::UErrorCode err = ::U_ZERO_ERROR;
85 if (err == ::U_BUFFER_OVERFLOW_ERROR) {
86 result.resize(length,
'?');
90 reinterpret_cast<::UChar *
>(result.data()),
96 error = ::U_FAILURE(err);
101 ::UErrorCode err = ::U_ZERO_ERROR;
107 reinterpret_cast<::UChar
const *
>(str.constData()),
111 if (err == ::U_BUFFER_OVERFLOW_ERROR) {
112 result.resize(length,
'?');
113 err = ::U_ZERO_ERROR;
118 reinterpret_cast<::UChar
const *
>(str.constData()),
122 error = ::U_FAILURE(err);
143{
return getConverter().
toUnicode(data, error); }
Converter & operator=(Converter &&)=delete
Converter(Converter const &)=delete
QByteArray fromUnicode(QString const &str, bool &error)
Converter & operator=(Converter const &)=delete
UConverter *const m_converter
Converter(Converter &&)=delete
QString toUnicode(QByteArray const &data, bool &error)
QStringList r(content.left(bodyIndex))
thread_local std::optional< Converter > tl_converter
Converter & getConverter()
QByteArray fromUnicode(QString const &str, bool &error)
QString toUnicode(QByteArray const &data, bool &error)