File indexing completed on 2024-04-14 14:18:30

0001 /*
0002     SPDX-FileCopyrightText: 2021 Friedrich W. H. Kossebau <kossebau@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KUSASCIITEXTCODEC_H
0008 #define KUSASCIITEXTCODEC_H
0009 
0010 #include <QTextCodec>
0011 
0012 // TODO KF6, remove this class, bug seems to be fixed in Qt6
0013 
0014 // Custom variant due to Qt-built-in not reporting encoding errors, see QTBUG-83081
0015 // Bug seems present since Qt 5.0 when ICU-based codecs were added
0016 // in 88d2e92b39ffd4a6ea9446498ad5a1cb208022a6 to the qtbase repo.
0017 // See KUsAsciiTextCodecTest::testBrokenBuiltinEncoding() for a test checking
0018 // the presence of the bug.
0019 class KUsAsciiTextCodec : public QTextCodec
0020 {
0021 public:
0022     KUsAsciiTextCodec() = default;
0023     ~KUsAsciiTextCodec() override = default;
0024 
0025 public: // QTextCodec API
0026     QByteArray name() const override;
0027     QList<QByteArray> aliases() const override;
0028     int mibEnum() const override;
0029 
0030 protected: // QTextCodec API
0031     QByteArray convertFromUnicode(const QChar *input, int number, QTextCodec::ConverterState *state) const override;
0032     QString convertToUnicode(const char *chars, int len, QTextCodec::ConverterState *state) const override;
0033 };
0034 
0035 #endif