1 /***************************************************************************
2  *   Copyright (C) 2004-2017 by Thomas Fischer <fischer@unix-ag.uni-kl.de> *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, see <https://www.gnu.org/licenses/>. *
16  ***************************************************************************/
17 
18 #ifndef BIBTEXENCODER_H
19 #define BIBTEXENCODER_H
20 
21 #include <QString>
22 
23 /**
24  * Base class for that convert between different textual representations
25  * for non-ASCII characters. Examples for external textual representations
26  * are \"a in LaTeX and &auml; in XML.
27  * @author Thomas Fischer <fischer@unix-ag.uni-kl.de>
28  */
29 class Encoder
30 {
31 public:
32     enum TargetEncoding {TargetEncodingASCII = 0, TargetEncodingUTF8 = 1};
33 
~Encoder()34     virtual ~Encoder() {
35         /// nothing
36     }
37 
38     /**
39      * Decode from external textual representation to internal (UTF-8) representation.
40      * @param text text in external textual representation
41      * @return text in internal (UTF-8) representation
42      */
43     virtual QString decode(const QString &text) const;
44 
45     /**
46      * Encode from internal (UTF-8) representation to external textual representation.
47      * Output may be restricted to ASCII (non-ASCII characters will be rewritten depending
48      * on concrete Encoder class, for example as '&#228;' as XML or '\"a' for LaTeX)
49      * or UTF-8 (all characters allowed, only 'special ones' rewritten, for example
50      * '&amp;' for XML and '\&' for LaTeX).
51      * @param text in internal (UTF-8) representation
52      * @param targetEncoding allow either only ASCII output or UTF-8 output.
53      * @return text text in external textual representation
54      */
55     virtual QString encode(const QString &text, const TargetEncoding targetEncoding) const;
56 };
57 
58 #endif
59