Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 andreas 1
/*
21 andreas 2
 * Copyright (C) 2020, 2021 by Andreas Theofilu <andreas@theosys.at>
2 andreas 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 3 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, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
 
19
#ifndef __TNAMEFORMAT_H__
20
#define __TNAMEFORMAT_H__
21
 
21 andreas 22
/** @file tnameformat.h
23
 * @brief Defines functions, classes and methods to convert strings from and
24
 * to different character sets. Mostly between the proprietary Windows
25
 * character set CP1250 and UTF-8.
26
 */
2 andreas 27
#include <string>
28
#include "terror.h"
29
 
21 andreas 30
/**
31
 * @struct CHTABLE
32
 * Defines the characters to co convert between CP1250 and UTF-8 character set.
33
 */
2 andreas 34
typedef struct
35
{
21 andreas 36
    unsigned char ch;   //!< CP1250 character
37
    short byte;         //!< UTF-8 byte sequence
2 andreas 38
}CHTABLE;
39
 
21 andreas 40
/**
41
 * Character set conversion table.
42
 */
2 andreas 43
static CHTABLE __cht[] = {
44
	{0x80,	0x20AC},
45
	{0x81,	0x0081},
46
	{0x82,	0x201A},
47
	{0x83,	0x0192},
48
	{0x84,	0x201E},
49
	{0x85,	0x2026},
50
	{0x86,	0x2020},
51
	{0x87,	0x2021},
52
	{0x88,	0x02C6},
53
	{0x89,	0x2030},
54
	{0x8A,	0x0160},
55
	{0x8B,	0x2039},
56
	{0x8C,	0x0152},
57
	{0x8D,	0x008d},
58
	{0x8E,	0x017D},
59
	{0x8F,	0x008f},
60
	{0x90,	0x0090},
61
	{0x91,	0x2018},
62
	{0x92,	0x2019},
63
	{0x93,	0x201C},
64
	{0x94,	0x201D},
65
	{0x95,	0x2022},
66
	{0x96,	0x2013},
67
	{0x97,	0x2014},
68
	{0x98,	0x02DC},
69
	{0x99,	0x2122},
70
	{0x9A,	0x0161},
71
	{0x9B,	0x203A},
72
	{0x9C,	0x0153},
73
	{0x9D,	0x009d},
74
	{0x9E,	0x017E},
75
	{0x9F,	0x0178},
76
	{0xA0,	0x00A0},
77
	{0xA1,	0x00A1},
78
	{0xA2,	0x00A2},
79
	{0xA3,	0x00A3},
80
	{0xA4,	0x00A4},
81
	{0xA5,	0x00A5},
82
	{0xA6,	0x00A6},
83
	{0xA7,	0x00A7},
84
	{0xA8,	0x00A8},
85
	{0xA9,	0x00A9},
86
	{0xAA,	0x00AA},
87
	{0xAB,	0x00AB},
88
	{0xAC,	0x00AC},
89
	{0xAD,	0x00AD},
90
	{0xAE,	0x00AE},
91
	{0xAF,	0x00AF},
92
	{0xB0,	0x00B0},
93
	{0xB1,	0x00B1},
94
	{0xB2,	0x00B2},
95
	{0xB3,	0x00B3},
96
	{0xB4,	0x00B4},
97
	{0xB5,	0x00B5},
98
	{0xB6,	0x00B6},
99
	{0xB7,	0x00B7},
100
	{0xB8,	0x00B8},
101
	{0xB9,	0x00B9},
102
	{0xBA,	0x00BA},
103
	{0xBB,	0x00BB},
104
	{0xBC,	0x00BC},
105
	{0xBD,	0x00BD},
106
	{0xBE,	0x00BE},
107
	{0xBF,	0x00BF},
108
	{0xC0,	0x00C0},
109
	{0xC1,	0x00C1},
110
	{0xC2,	0x00C2},
111
	{0xC3,	0x00C3},
112
	{0xC4,	0x00C4},
113
	{0xC5,	0x00C5},
114
	{0xC6,	0x00C6},
115
	{0xC7,	0x00C7},
116
	{0xC8,	0x00C8},
117
	{0xC9,	0x00C9},
118
	{0xCA,	0x00CA},
119
	{0xCB,	0x00CB},
120
	{0xCC,	0x00CC},
121
	{0xCD,	0x00CD},
122
	{0xCE,	0x00CE},
123
	{0xCF,	0x00CF},
124
	{0xD0,	0x00D0},
125
	{0xD1,	0x00D1},
126
	{0xD2,	0x00D2},
127
	{0xD3,	0x00D3},
128
	{0xD4,	0x00D4},
129
	{0xD5,	0x00D5},
130
	{0xD6,	0x00D6},
131
	{0xD7,	0x00D7},
132
	{0xD8,	0x00D8},
133
	{0xD9,	0x00D9},
134
	{0xDA,	0x00DA},
135
	{0xDB,	0x00DB},
136
	{0xDC,	0x00DC},
137
	{0xDD,	0x00DD},
138
	{0xDE,	0x00DE},
139
	{0xDF,	0x00DF},
140
	{0xE0,	0x00E0},
141
	{0xE1,	0x00E1},
142
	{0xE2,	0x00E2},
143
	{0xE3,	0x00E3},
144
	{0xE4,	0x00E4},
145
	{0xE5,	0x00E5},
146
	{0xE6,	0x00E6},
147
	{0xE7,	0x00E7},
148
	{0xE8,	0x00E8},
149
	{0xE9,	0x00E9},
150
	{0xEA,	0x00EA},
151
	{0xEB,	0x00EB},
152
	{0xEC,	0x00EC},
153
	{0xED,	0x00ED},
154
	{0xEE,	0x00EE},
155
	{0xEF,	0x00EF},
156
	{0xF0,	0x00F0},
157
	{0xF1,	0x00F1},
158
	{0xF2,	0x00F2},
159
	{0xF3,	0x00F3},
160
	{0xF4,	0x00F4},
161
	{0xF5,	0x00F5},
162
	{0xF6,	0x00F6},
163
	{0xF7,	0x00F7},
164
	{0xF8,	0x00F8},
165
	{0xF9,	0x00F9},
166
	{0xFA,	0x00FA},
167
	{0xFB,	0x00FB},
168
	{0xFC,	0x00FC},
169
	{0xFD,	0x00FD},
170
	{0xFE,	0x00FE},
171
	{0xFF,	0x00FF}
172
};
173
 
21 andreas 174
/**
175
 * @brief The TNameFormat class
176
 * Defines some static methods to convert character sets and some other
177
 * methods.
178
 */
2 andreas 179
class TNameFormat
180
{
181
	public:
182
		TNameFormat();
183
		~TNameFormat();
184
 
185
		static std::string toValidName(std::string& str);
186
		static std::string cutNumbers(std::string& str);
187
		static std::string toShortName(std::string& str);
188
		static std::string transFontName(std::string& str);
189
		static std::string toURL(std::string& str);
190
		static char *EncodeTo(char *buf, size_t *len, const std::string& str, const std::string& from, const std::string& to);
191
		static std::string textToWeb(const std::string& txt);
192
		static std::string toHex(int num, int width);
193
		static std::string strToHex(std::string str, int width, bool format = false, int indent = 0);
67 andreas 194
        static std::string strToHex(const unsigned char *str, size_t len, int width, bool format = false, int indent = 0);
2 andreas 195
		static std::string latin1ToUTF8(const std::string& str);
196
		static std::string cp1250ToUTF8(const std::string& str);
197
		static std::string UTF8ToCp1250(const std::string& str);
44 andreas 198
        static std::string trimXML(const std::string& str);
2 andreas 199
 
200
	private:
201
		static std::string& replace(const std::string& str, const std::string& old, const std::string& neu);
202
 
203
		static std::string mStr;
204
};
205
 
206
#endif
207