File indexing completed on 2025-01-05 04:01:13

0001 /*
0002  * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 #include <QtGlobal>
0007 
0008 #include "io/aep/string_decoder.hpp"
0009 
0010 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
0011 
0012 #include <QStringConverter>
0013 QString glaxnimate::io::aep::decode_string(const QByteArray& data)
0014 {
0015     auto encoding = QStringConverter::encodingForData(data);
0016     if ( encoding )
0017         return QStringDecoder(*encoding).decode(data);
0018     return QStringDecoder(QStringConverter::Utf8).decode(data);
0019 }
0020 
0021 QString glaxnimate::io::aep::decode_utf16(const QByteArray& data, bool big_endian)
0022 {
0023     auto encoding = big_endian ? QStringConverter::Utf16BE : QStringConverter::Utf16LE;
0024     return QStringDecoder(encoding).decode(data);
0025 }
0026 
0027 #else
0028 
0029 #include <QTextCodec>
0030 QString glaxnimate::io::aep::decode_string(const QByteArray& data)
0031 {
0032     auto utf8 = QTextCodec::codecForName("UTF-8");
0033     auto encoding = QTextCodec::codecForUtfText(data, utf8);
0034     return encoding->toUnicode(data);
0035 }
0036 
0037 QString glaxnimate::io::aep::decode_utf16(const QByteArray& data, bool big_endian)
0038 {
0039     const char* name = big_endian ? "UFT-16BE" : "UFT-16BE";
0040     auto encoding = QTextCodec::codecForName(name);
0041     return encoding->toUnicode(data);
0042 }
0043 
0044 #endif
0045