File indexing completed on 2024-06-23 04:30:52

0001 /*
0002     Kchmviewer - a CHM and EPUB file viewer with broad language support
0003     SPDX-FileCopyrightText: 2004-2014 George Yunaev gyunaev@ulduzsoft.com
0004 
0005     SPDX-License-Identifier: GPL-3.0-or-later
0006 */
0007 
0008 #ifndef HELPER_ENTITYDECODER_H
0009 #define HELPER_ENTITYDECODER_H
0010 
0011 #include <QMap>
0012 #include <QString>
0013 
0014 //
0015 // This helper class decodes the Unicode HTML entities into the Unicode characters
0016 //
0017 class HelperEntityDecoder
0018 {
0019 public:
0020     // Initialization with the specific decoder
0021     explicit HelperEntityDecoder(QTextCodec *encoder = nullptr);
0022 
0023     // Used when the encoding changes
0024     void changeEncoding(QTextCodec *encoder = nullptr);
0025 
0026     // The decoder function
0027     QString decode(const QString &entity) const;
0028 
0029 private:
0030     // Map to decode HTML entitles like &acute; based on current encoding, initialized upon the first use
0031     QMap<QString, QString> m_entityDecodeMap;
0032 };
0033 
0034 #endif // HELPER_ENTITYDECODER_H