File indexing completed on 2024-05-05 17:57:59

0001 /*
0002     This file is part of the Okteta Core library, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2004, 2011 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef OKTETA_TEXTCHARCODEC_HPP
0010 #define OKTETA_TEXTCHARCODEC_HPP
0011 
0012 // lib
0013 #include <charcodec.hpp>
0014 // Qt
0015 #include <QString>
0016 
0017 class QTextCodec;
0018 class QTextDecoder;
0019 class QTextEncoder;
0020 
0021 namespace Okteta {
0022 
0023 // used by all codecs with full char coping, i.e. there are no undefined chars
0024 class TextCharCodec : public CharCodec
0025 {
0026 public:
0027     static TextCharCodec* createCodec(const QString& codeName);
0028     static TextCharCodec* createCodec(CharCoding charCoding);
0029     static TextCharCodec* createLocalCodec();
0030 
0031     static const QStringList& codecNames();
0032 
0033 public:
0034     TextCharCodec(const TextCharCodec&) = delete;
0035     ~TextCharCodec() override;
0036 
0037     TextCharCodec& operator=(const TextCharCodec&) = delete;
0038 
0039 protected:
0040     explicit TextCharCodec(QTextCodec* textCodec);
0041 
0042 public: // CharCodec API
0043     Character decode(Byte byte) const override;
0044     bool encode(Byte* byte, const QChar& _char) const override;
0045     bool canEncode(const QChar& _char) const override;
0046     const QString& name() const override;
0047 
0048 private:
0049     QTextCodec* mCodec;
0050     /** decodes the chars to unicode */
0051     QTextDecoder* mDecoder;
0052     /** encodes the chars from unicode */
0053     QTextEncoder* mEncoder;
0054     /** */
0055     mutable QString mName;
0056 };
0057 
0058 }
0059 
0060 #endif