/src/espeak-ng/src/libespeak-ng/encoding.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 2017 Reece H. Dunn |
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, see: <http://www.gnu.org/licenses/>. |
16 | | */ |
17 | | |
18 | | #include "config.h" |
19 | | |
20 | | #include <string.h> |
21 | | #include <stdint.h> |
22 | | #include <stdlib.h> |
23 | | #include <wchar.h> |
24 | | |
25 | | #include <espeak-ng/espeak_ng.h> |
26 | | #include <espeak-ng/encoding.h> |
27 | | |
28 | | #include <espeak-ng/encoding.h> // for espeak_ng_TEXT_DECODER, ESPEAKNG_EN... |
29 | | #include "espeak-ng/speak_lib.h" // for espeakCHARS_16BIT, espeakCHARS_8BIT |
30 | | #include "mnemonics.h" // for LookupMnem, MNEM_TAB |
31 | | #include "translate.h" // for LEADING_2_BITS, UTF8_TAIL_BITS |
32 | | |
33 | | // http://www.iana.org/assignments/character-sets/character-sets.xhtml |
34 | | static const MNEM_TAB mnem_encoding[] = { |
35 | | { "ANSI_X3.4-1968", ESPEAKNG_ENCODING_US_ASCII }, |
36 | | { "ANSI_X3.4-1986", ESPEAKNG_ENCODING_US_ASCII }, |
37 | | { "ASMO-708", ESPEAKNG_ENCODING_ISO_8859_6 }, |
38 | | { "ECMA-114", ESPEAKNG_ENCODING_ISO_8859_6 }, |
39 | | { "ECMA-118", ESPEAKNG_ENCODING_ISO_8859_7 }, |
40 | | { "ELOT_928", ESPEAKNG_ENCODING_ISO_8859_7 }, |
41 | | { "IBM367", ESPEAKNG_ENCODING_US_ASCII }, |
42 | | { "IBM819", ESPEAKNG_ENCODING_ISO_8859_1 }, |
43 | | { "ISCII", ESPEAKNG_ENCODING_ISCII }, |
44 | | { "ISO_646.irv:1991", ESPEAKNG_ENCODING_US_ASCII }, |
45 | | { "ISO_8859-1", ESPEAKNG_ENCODING_ISO_8859_1 }, |
46 | | { "ISO_8859-1:1987", ESPEAKNG_ENCODING_ISO_8859_1 }, |
47 | | { "ISO_8859-2", ESPEAKNG_ENCODING_ISO_8859_2 }, |
48 | | { "ISO_8859-2:1987", ESPEAKNG_ENCODING_ISO_8859_2 }, |
49 | | { "ISO_8859-3", ESPEAKNG_ENCODING_ISO_8859_3 }, |
50 | | { "ISO_8859-3:1988", ESPEAKNG_ENCODING_ISO_8859_3 }, |
51 | | { "ISO_8859-4", ESPEAKNG_ENCODING_ISO_8859_4 }, |
52 | | { "ISO_8859-4:1988", ESPEAKNG_ENCODING_ISO_8859_4 }, |
53 | | { "ISO_8859-5", ESPEAKNG_ENCODING_ISO_8859_5 }, |
54 | | { "ISO_8859-5:1988", ESPEAKNG_ENCODING_ISO_8859_5 }, |
55 | | { "ISO_8859-6", ESPEAKNG_ENCODING_ISO_8859_6 }, |
56 | | { "ISO_8859-6:1987", ESPEAKNG_ENCODING_ISO_8859_6 }, |
57 | | { "ISO_8859-7", ESPEAKNG_ENCODING_ISO_8859_7 }, |
58 | | { "ISO_8859-7:1987", ESPEAKNG_ENCODING_ISO_8859_7 }, |
59 | | { "ISO_8859-8", ESPEAKNG_ENCODING_ISO_8859_8 }, |
60 | | { "ISO_8859-8:1988", ESPEAKNG_ENCODING_ISO_8859_8 }, |
61 | | { "ISO_8859-9", ESPEAKNG_ENCODING_ISO_8859_9 }, |
62 | | { "ISO_8859-9:1989", ESPEAKNG_ENCODING_ISO_8859_9 }, |
63 | | { "ISO_8859-10", ESPEAKNG_ENCODING_ISO_8859_10 }, |
64 | | { "ISO_8859-10:1992", ESPEAKNG_ENCODING_ISO_8859_10 }, |
65 | | { "ISO_8859-14", ESPEAKNG_ENCODING_ISO_8859_14 }, |
66 | | { "ISO_8859-14:1998", ESPEAKNG_ENCODING_ISO_8859_14 }, |
67 | | { "ISO_8859-15", ESPEAKNG_ENCODING_ISO_8859_15 }, |
68 | | { "ISO_8859-16", ESPEAKNG_ENCODING_ISO_8859_16 }, |
69 | | { "ISO_8859-16:2001", ESPEAKNG_ENCODING_ISO_8859_16 }, |
70 | | { "ISO646-US", ESPEAKNG_ENCODING_US_ASCII }, |
71 | | { "ISO-10646-UCS-2", ESPEAKNG_ENCODING_ISO_10646_UCS_2 }, |
72 | | { "ISO-8859-1", ESPEAKNG_ENCODING_ISO_8859_1 }, |
73 | | { "ISO-8859-2", ESPEAKNG_ENCODING_ISO_8859_2 }, |
74 | | { "ISO-8859-3", ESPEAKNG_ENCODING_ISO_8859_3 }, |
75 | | { "ISO-8859-4", ESPEAKNG_ENCODING_ISO_8859_4 }, |
76 | | { "ISO-8859-5", ESPEAKNG_ENCODING_ISO_8859_5 }, |
77 | | { "ISO-8859-6", ESPEAKNG_ENCODING_ISO_8859_6 }, |
78 | | { "ISO-8859-7", ESPEAKNG_ENCODING_ISO_8859_7 }, |
79 | | { "ISO-8859-8", ESPEAKNG_ENCODING_ISO_8859_8 }, |
80 | | { "ISO-8859-9", ESPEAKNG_ENCODING_ISO_8859_9 }, |
81 | | { "ISO-8859-10", ESPEAKNG_ENCODING_ISO_8859_10 }, |
82 | | { "ISO-8859-11", ESPEAKNG_ENCODING_ISO_8859_11 }, |
83 | | { "ISO-8859-13", ESPEAKNG_ENCODING_ISO_8859_13 }, |
84 | | { "ISO-8859-14", ESPEAKNG_ENCODING_ISO_8859_14 }, |
85 | | { "ISO-8859-15", ESPEAKNG_ENCODING_ISO_8859_15 }, |
86 | | { "ISO-8859-16", ESPEAKNG_ENCODING_ISO_8859_16 }, |
87 | | { "KOI8-R", ESPEAKNG_ENCODING_KOI8_R }, |
88 | | { "Latin-9", ESPEAKNG_ENCODING_ISO_8859_15 }, |
89 | | { "TIS-620", ESPEAKNG_ENCODING_ISO_8859_11 }, |
90 | | { "US-ASCII", ESPEAKNG_ENCODING_US_ASCII }, |
91 | | { "UTF-8", ESPEAKNG_ENCODING_UTF_8 }, |
92 | | { "cp367", ESPEAKNG_ENCODING_US_ASCII }, |
93 | | { "cp819", ESPEAKNG_ENCODING_ISO_8859_1 }, |
94 | | { "csASCII", ESPEAKNG_ENCODING_US_ASCII }, |
95 | | { "csISO885913", ESPEAKNG_ENCODING_ISO_8859_13 }, |
96 | | { "csISO885914", ESPEAKNG_ENCODING_ISO_8859_14 }, |
97 | | { "csISO885915", ESPEAKNG_ENCODING_ISO_8859_15 }, |
98 | | { "csISO885916", ESPEAKNG_ENCODING_ISO_8859_16 }, |
99 | | { "csISOLatin1", ESPEAKNG_ENCODING_ISO_8859_1 }, |
100 | | { "csISOLatin2", ESPEAKNG_ENCODING_ISO_8859_2 }, |
101 | | { "csISOLatin3", ESPEAKNG_ENCODING_ISO_8859_3 }, |
102 | | { "csISOLatin4", ESPEAKNG_ENCODING_ISO_8859_4 }, |
103 | | { "csISOLatin5", ESPEAKNG_ENCODING_ISO_8859_9 }, |
104 | | { "csISOLatin6", ESPEAKNG_ENCODING_ISO_8859_10 }, |
105 | | { "csISOLatinArabic", ESPEAKNG_ENCODING_ISO_8859_6 }, |
106 | | { "csISOLatinCyrillic",ESPEAKNG_ENCODING_ISO_8859_5 }, |
107 | | { "csISOLatinGreek", ESPEAKNG_ENCODING_ISO_8859_7 }, |
108 | | { "csISOLatinHebrew", ESPEAKNG_ENCODING_ISO_8859_8 }, |
109 | | { "csKOI8R", ESPEAKNG_ENCODING_KOI8_R }, |
110 | | { "csTIS620", ESPEAKNG_ENCODING_ISO_8859_11 }, |
111 | | { "csUTF8", ESPEAKNG_ENCODING_UTF_8 }, |
112 | | { "csUnicode", ESPEAKNG_ENCODING_ISO_10646_UCS_2 }, |
113 | | { "arabic", ESPEAKNG_ENCODING_ISO_8859_6 }, |
114 | | { "cyrillic", ESPEAKNG_ENCODING_ISO_8859_5 }, |
115 | | { "greek", ESPEAKNG_ENCODING_ISO_8859_7 }, |
116 | | { "greek8", ESPEAKNG_ENCODING_ISO_8859_7 }, |
117 | | { "hebrew", ESPEAKNG_ENCODING_ISO_8859_8 }, |
118 | | { "iso-celtic", ESPEAKNG_ENCODING_ISO_8859_14 }, |
119 | | { "iso-ir-6", ESPEAKNG_ENCODING_US_ASCII }, |
120 | | { "iso-ir-100", ESPEAKNG_ENCODING_ISO_8859_1 }, |
121 | | { "iso-ir-101", ESPEAKNG_ENCODING_ISO_8859_2 }, |
122 | | { "iso-ir-109", ESPEAKNG_ENCODING_ISO_8859_3 }, |
123 | | { "iso-ir-110", ESPEAKNG_ENCODING_ISO_8859_4 }, |
124 | | { "iso-ir-126", ESPEAKNG_ENCODING_ISO_8859_7 }, |
125 | | { "iso-ir-127", ESPEAKNG_ENCODING_ISO_8859_6 }, |
126 | | { "iso-ir-138", ESPEAKNG_ENCODING_ISO_8859_8 }, |
127 | | { "iso-ir-144", ESPEAKNG_ENCODING_ISO_8859_5 }, |
128 | | { "iso-ir-148", ESPEAKNG_ENCODING_ISO_8859_9 }, |
129 | | { "iso-ir-157", ESPEAKNG_ENCODING_ISO_8859_10 }, |
130 | | { "iso-ir-199", ESPEAKNG_ENCODING_ISO_8859_14 }, |
131 | | { "iso-ir-226", ESPEAKNG_ENCODING_ISO_8859_16 }, |
132 | | { "latin1", ESPEAKNG_ENCODING_ISO_8859_1 }, |
133 | | { "latin2", ESPEAKNG_ENCODING_ISO_8859_2 }, |
134 | | { "latin3", ESPEAKNG_ENCODING_ISO_8859_3 }, |
135 | | { "latin4", ESPEAKNG_ENCODING_ISO_8859_4 }, |
136 | | { "latin5", ESPEAKNG_ENCODING_ISO_8859_9 }, |
137 | | { "latin6", ESPEAKNG_ENCODING_ISO_8859_10 }, |
138 | | { "latin8", ESPEAKNG_ENCODING_ISO_8859_14 }, |
139 | | { "latin10", ESPEAKNG_ENCODING_ISO_8859_16 }, |
140 | | { "l1", ESPEAKNG_ENCODING_ISO_8859_1 }, |
141 | | { "l2", ESPEAKNG_ENCODING_ISO_8859_2 }, |
142 | | { "l3", ESPEAKNG_ENCODING_ISO_8859_3 }, |
143 | | { "l4", ESPEAKNG_ENCODING_ISO_8859_4 }, |
144 | | { "l5", ESPEAKNG_ENCODING_ISO_8859_9 }, |
145 | | { "l6", ESPEAKNG_ENCODING_ISO_8859_10 }, |
146 | | { "l8", ESPEAKNG_ENCODING_ISO_8859_14 }, |
147 | | { "l10", ESPEAKNG_ENCODING_ISO_8859_16 }, |
148 | | { "us", ESPEAKNG_ENCODING_US_ASCII }, |
149 | | { NULL, ESPEAKNG_ENCODING_UNKNOWN } |
150 | | }; |
151 | | |
152 | | #pragma GCC visibility push(default) |
153 | | |
154 | | espeak_ng_ENCODING |
155 | | espeak_ng_EncodingFromName(const char *encoding) |
156 | 0 | { |
157 | 0 | return LookupMnem(mnem_encoding, encoding); |
158 | 0 | } |
159 | | |
160 | | #pragma GCC visibility pop |
161 | | |
162 | | struct espeak_ng_TEXT_DECODER_ |
163 | | { |
164 | | const uint8_t *current; |
165 | | const uint8_t *end; |
166 | | |
167 | | uint32_t (*get)(espeak_ng_TEXT_DECODER *decoder); |
168 | | const uint16_t *codepage; |
169 | | }; |
170 | | |
171 | | // Reference: http://www.iana.org/go/rfc1345 |
172 | | // Reference: http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-1.TXT |
173 | | static const uint16_t ISO_8859_1[0x80] = { |
174 | | 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, // 80 |
175 | | 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, // 88 |
176 | | 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, // 90 |
177 | | 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, // 98 |
178 | | 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, // a0 |
179 | | 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, // a8 |
180 | | 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, // b0 |
181 | | 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, // b8 |
182 | | 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, // c0 |
183 | | 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8 |
184 | | 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, // d0 |
185 | | 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, // d8 |
186 | | 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, // e0 |
187 | | 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8 |
188 | | 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, // f0 |
189 | | 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff, // f8 |
190 | | }; |
191 | | |
192 | | // Reference: http://www.iana.org/go/rfc1345 |
193 | | // Reference: http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-2.TXT |
194 | | static const uint16_t ISO_8859_2[0x80] = { |
195 | | 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, // 80 |
196 | | 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, // 88 |
197 | | 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, // 90 |
198 | | 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, // 98 |
199 | | 0x00a0, 0x0104, 0x02d8, 0x0141, 0x00a4, 0x013d, 0x015a, 0x00a7, // a0 |
200 | | 0x00a8, 0x0160, 0x015e, 0x0164, 0x0179, 0x00ad, 0x017d, 0x017b, // a8 |
201 | | 0x00b0, 0x0105, 0x02db, 0x0142, 0x00b4, 0x013e, 0x015b, 0x02c7, // b0 |
202 | | 0x00b8, 0x0161, 0x015f, 0x0165, 0x017a, 0x02dd, 0x017e, 0x017c, // b8 |
203 | | 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, // c0 |
204 | | 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e, // c8 |
205 | | 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, // d0 |
206 | | 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df, // d8 |
207 | | 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, // e0 |
208 | | 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f, // e8 |
209 | | 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, // f0 |
210 | | 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9, // f8 |
211 | | }; |
212 | | |
213 | | // Reference: http://www.iana.org/go/rfc1345 |
214 | | // Reference: http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-3.TXT |
215 | | static const uint16_t ISO_8859_3[0x80] = { |
216 | | 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, // 80 |
217 | | 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, // 88 |
218 | | 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, // 90 |
219 | | 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, // 98 |
220 | | 0x00a0, 0x0126, 0x02d8, 0x00a3, 0x00a4, 0xfffd, 0x0124, 0x00a7, // a0 |
221 | | 0x00a8, 0x0130, 0x015e, 0x011e, 0x0134, 0x00ad, 0xfffd, 0x017b, // a8 |
222 | | 0x00b0, 0x0127, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x0125, 0x00b7, // b0 |
223 | | 0x00b8, 0x0131, 0x015f, 0x011f, 0x0135, 0x00bd, 0xfffd, 0x017c, // b8 |
224 | | 0x00c0, 0x00c1, 0x00c2, 0xfffd, 0x00c4, 0x010a, 0x0108, 0x00c7, // c0 |
225 | | 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8 |
226 | | 0xfffd, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x0120, 0x00d6, 0x00d7, // d0 |
227 | | 0x011c, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x016c, 0x015c, 0x00df, // d8 |
228 | | 0x00e0, 0x00e1, 0x00e2, 0xfffd, 0x00e4, 0x010b, 0x0109, 0x00e7, // e0 |
229 | | 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8 |
230 | | 0xfffd, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x0121, 0x00f6, 0x00f7, // f0 |
231 | | 0x011d, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x016d, 0x015d, 0x02d9, // f8 |
232 | | }; |
233 | | |
234 | | // Reference: http://www.iana.org/go/rfc1345 |
235 | | // Reference: http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-4.TXT |
236 | | static const uint16_t ISO_8859_4[0x80] = { |
237 | | 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, // 80 |
238 | | 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, // 88 |
239 | | 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, // 90 |
240 | | 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, // 98 |
241 | | 0x00a0, 0x0104, 0x0138, 0x0156, 0x00a4, 0x0128, 0x013b, 0x00a7, // a0 |
242 | | 0x00a8, 0x0160, 0x0112, 0x0122, 0x0166, 0x00ad, 0x017d, 0x00af, // a8 |
243 | | 0x00b0, 0x0105, 0x02db, 0x0157, 0x00b4, 0x0129, 0x013c, 0x02c7, // b0 |
244 | | 0x00b8, 0x0161, 0x0113, 0x0123, 0x0167, 0x014a, 0x017e, 0x014b, // b8 |
245 | | 0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e, // c0 |
246 | | 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x012a, // c8 |
247 | | 0x0110, 0x0145, 0x014c, 0x0136, 0x00d4, 0x00d5, 0x00d6, 0x00d7, // d0 |
248 | | 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x0168, 0x016a, 0x00df, // d8 |
249 | | 0x0101, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x012f, // e0 |
250 | | 0x010d, 0x00e9, 0x0119, 0x00eb, 0x0117, 0x00ed, 0x00ee, 0x012b, // e8 |
251 | | 0x0111, 0x0146, 0x014d, 0x0137, 0x00f4, 0x00f5, 0x00f6, 0x00f7, // f0 |
252 | | 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x0169, 0x016b, 0x02d9, // f8 |
253 | | }; |
254 | | |
255 | | // Reference: http://www.iana.org/go/rfc1345 |
256 | | // Reference: http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-5.TXT |
257 | | static const uint16_t ISO_8859_5[0x80] = { |
258 | | 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, // 80 |
259 | | 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, // 88 |
260 | | 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, // 90 |
261 | | 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, // 98 |
262 | | 0x00a0, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, // a0 |
263 | | 0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x00ad, 0x040e, 0x040f, // a8 |
264 | | 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, // b0 |
265 | | 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f, // b8 |
266 | | 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, // c0 |
267 | | 0x0428, 0x0429, 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f, // c8 |
268 | | 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, // d0 |
269 | | 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, 0x043f, // d8 |
270 | | 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, // e0 |
271 | | 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, 0x044e, 0x044f, // e8 |
272 | | 0x2116, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457, // f0 |
273 | | 0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x00a7, 0x045e, 0x045f, // f8 |
274 | | }; |
275 | | |
276 | | // Reference: http://www.iana.org/go/rfc1345 |
277 | | // Reference: http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-6.TXT |
278 | | static const uint16_t ISO_8859_6[0x80] = { |
279 | | 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, // 80 |
280 | | 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, // 88 |
281 | | 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, // 90 |
282 | | 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, // 98 |
283 | | 0x00a0, 0xfffd, 0xfffd, 0xfffd, 0x00a4, 0xfffd, 0xfffd, 0xfffd, // a0 |
284 | | 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0x060c, 0x00ad, 0xfffd, 0xfffd, // a8 |
285 | | 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // b0 |
286 | | 0xfffd, 0xfffd, 0xfffd, 0x061b, 0xfffd, 0xfffd, 0xfffd, 0x061f, // b8 |
287 | | 0xfffd, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627, // c0 |
288 | | 0x0628, 0x0629, 0x062a, 0x062b, 0x062c, 0x062d, 0x062e, 0x062f, // c8 |
289 | | 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x0637, // d0 |
290 | | 0x0638, 0x0639, 0x063a, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // d8 |
291 | | 0x0640, 0x0641, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647, // e0 |
292 | | 0x0648, 0x0649, 0x064a, 0x064b, 0x064c, 0x064d, 0x064e, 0x064f, // e8 |
293 | | 0x0650, 0x0651, 0x0652, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // f0 |
294 | | 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // f8 |
295 | | }; |
296 | | |
297 | | // Reference: http://www.iana.org/go/rfc1345 |
298 | | // Reference: http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-7.TXT |
299 | | static const uint16_t ISO_8859_7[0x80] = { |
300 | | 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, // 80 |
301 | | 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, // 88 |
302 | | 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, // 90 |
303 | | 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, // 98 |
304 | | 0x00a0, 0x2018, 0x2019, 0x00a3, 0x20ac, 0x20af, 0x00a6, 0x00a7, // a0 |
305 | | 0x00a8, 0x00a9, 0x037a, 0x00ab, 0x00ac, 0x00ad, 0xfffd, 0x2015, // a8 |
306 | | 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x0384, 0x0385, 0x0386, 0x00b7, // b0 |
307 | | 0x0388, 0x0389, 0x038a, 0x00bb, 0x038c, 0x00bd, 0x038e, 0x038f, // b8 |
308 | | 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, // c0 |
309 | | 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f, // c8 |
310 | | 0x03a0, 0x03a1, 0xfffd, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7, // d0 |
311 | | 0x03a8, 0x03a9, 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03ae, 0x03af, // d8 |
312 | | 0x03b0, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, // e0 |
313 | | 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, // e8 |
314 | | 0x03c0, 0x03c1, 0x03c2, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, // f0 |
315 | | 0x03c8, 0x03c9, 0x03ca, 0x03cb, 0x03cc, 0x03cd, 0x03ce, 0xfffd, // f8 |
316 | | }; |
317 | | |
318 | | // Reference: http://www.iana.org/go/rfc1345 |
319 | | // Reference: http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-8.TXT |
320 | | static const uint16_t ISO_8859_8[0x80] = { |
321 | | 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, // 80 |
322 | | 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, // 88 |
323 | | 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, // 90 |
324 | | 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, // 98 |
325 | | 0x00a0, 0xfffd, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, // a0 |
326 | | 0x00a8, 0x00a9, 0x00d7, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, // a8 |
327 | | 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, // b0 |
328 | | 0x00b8, 0x00b9, 0x00f7, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0xfffd, // b8 |
329 | | 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // c0 |
330 | | 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // c8 |
331 | | 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // d0 |
332 | | 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0x2017, // d8 |
333 | | 0x05d0, 0x05d1, 0x05d2, 0x05d3, 0x05d4, 0x05d5, 0x05d6, 0x05d7, // e0 |
334 | | 0x05d8, 0x05d9, 0x05da, 0x05db, 0x05dc, 0x05dd, 0x05de, 0x05df, // e8 |
335 | | 0x05e0, 0x05e1, 0x05e2, 0x05e3, 0x05e4, 0x05e5, 0x05e6, 0x05e7, // f0 |
336 | | 0x05e8, 0x05e9, 0x05ea, 0xfffd, 0xfffd, 0x200e, 0x200f, 0xfffd, // f8 |
337 | | }; |
338 | | |
339 | | // Reference: http://www.iana.org/go/rfc1345 |
340 | | // Reference: http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-9.TXT |
341 | | static const uint16_t ISO_8859_9[0x80] = { |
342 | | 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, // 80 |
343 | | 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, // 88 |
344 | | 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, // 90 |
345 | | 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, // 98 |
346 | | 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, // a0 |
347 | | 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, // a8 |
348 | | 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, // b0 |
349 | | 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, // b8 |
350 | | 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, // c0 |
351 | | 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8 |
352 | | 0x011e, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, // d0 |
353 | | 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x0130, 0x015e, 0x00df, // d8 |
354 | | 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, // e0 |
355 | | 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8 |
356 | | 0x011f, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, // f0 |
357 | | 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0131, 0x015f, 0x00ff, // f8 |
358 | | }; |
359 | | |
360 | | // Reference: http://www.iana.org/go/rfc1345 |
361 | | // Reference: http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-10.TXT |
362 | | static const uint16_t ISO_8859_10[0x80] = { |
363 | | 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, // 80 |
364 | | 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, // 88 |
365 | | 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, // 90 |
366 | | 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, // 98 |
367 | | 0x00a0, 0x0104, 0x0112, 0x0122, 0x012a, 0x0128, 0x0136, 0x00a7, // a0 |
368 | | 0x013b, 0x0110, 0x0160, 0x0166, 0x017d, 0x00ad, 0x016a, 0x014a, // a8 |
369 | | 0x00b0, 0x0105, 0x0113, 0x0123, 0x012b, 0x0129, 0x0137, 0x00b7, // b0 |
370 | | 0x013c, 0x0111, 0x0161, 0x0167, 0x017e, 0x2015, 0x016b, 0x014b, // b8 |
371 | | 0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e, // c0 |
372 | | 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x00cf, // c8 |
373 | | 0x00d0, 0x0145, 0x014c, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x0168, // d0 |
374 | | 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, // d8 |
375 | | 0x0101, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x012f, // e0 |
376 | | 0x010d, 0x00e9, 0x0119, 0x00eb, 0x0117, 0x00ed, 0x00ee, 0x00ef, // e8 |
377 | | 0x00f0, 0x0146, 0x014d, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x0169, // f0 |
378 | | 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x0138, // f8 |
379 | | }; |
380 | | |
381 | | // Reference: http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-11.TXT |
382 | | static const uint16_t ISO_8859_11[0x80] = { |
383 | | 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, // 80 |
384 | | 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, // 88 |
385 | | 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, // 90 |
386 | | 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, // 98 |
387 | | 0x00a0, 0x0e01, 0x0e02, 0x0e03, 0x0e04, 0x0e05, 0x0e06, 0x0e07, // a0 |
388 | | 0x0e08, 0x0e09, 0x0e0a, 0x0e0b, 0x0e0c, 0x0e0d, 0x0e0e, 0x0e0f, // a8 |
389 | | 0x0e10, 0x0e11, 0x0e12, 0x0e13, 0x0e14, 0x0e15, 0x0e16, 0x0e17, // b0 |
390 | | 0x0e18, 0x0e19, 0x0e1a, 0x0e1b, 0x0e1c, 0x0e1d, 0x0e1e, 0x0e1f, // b8 |
391 | | 0x0e20, 0x0e21, 0x0e22, 0x0e23, 0x0e24, 0x0e25, 0x0e26, 0x0e27, // c0 |
392 | | 0x0e28, 0x0e29, 0x0e2a, 0x0e2b, 0x0e2c, 0x0e2d, 0x0e2e, 0x0e2f, // c8 |
393 | | 0x0e30, 0x0e31, 0x0e32, 0x0e33, 0x0e34, 0x0e35, 0x0e36, 0x0e37, // d0 |
394 | | 0x0e38, 0x0e39, 0x0e3a, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0x0e3f, // d8 |
395 | | 0x0e40, 0x0e41, 0x0e42, 0x0e43, 0x0e44, 0x0e45, 0x0e46, 0x0e47, // e0 |
396 | | 0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c, 0x0e4d, 0x0e4e, 0x0e4f, // e8 |
397 | | 0x0e50, 0x0e51, 0x0e52, 0x0e53, 0x0e54, 0x0e55, 0x0e56, 0x0e57, // f0 |
398 | | 0x0e58, 0x0e59, 0x0e5a, 0x0e5b, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // f8 |
399 | | }; |
400 | | |
401 | | // Reference: http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-13.TXT |
402 | | static const uint16_t ISO_8859_13[0x80] = { |
403 | | 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, // 80 |
404 | | 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, // 88 |
405 | | 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, // 90 |
406 | | 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, // 98 |
407 | | 0x00a0, 0x201d, 0x00a2, 0x00a3, 0x00a4, 0x201e, 0x00a6, 0x00a7, // a0 |
408 | | 0x00d8, 0x00a9, 0x0156, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00c6, // a8 |
409 | | 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x201c, 0x00b5, 0x00b6, 0x00b7, // b0 |
410 | | 0x00f8, 0x00b9, 0x0157, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00e6, // b8 |
411 | | 0x0104, 0x012e, 0x0100, 0x0106, 0x00c4, 0x00c5, 0x0118, 0x0112, // c0 |
412 | | 0x010c, 0x00c9, 0x0179, 0x0116, 0x0122, 0x0136, 0x012a, 0x013b, // c8 |
413 | | 0x0160, 0x0143, 0x0145, 0x00d3, 0x014c, 0x00d5, 0x00d6, 0x00d7, // d0 |
414 | | 0x0172, 0x0141, 0x015a, 0x016a, 0x00dc, 0x017b, 0x017d, 0x00df, // d8 |
415 | | 0x0105, 0x012f, 0x0101, 0x0107, 0x00e4, 0x00e5, 0x0119, 0x0113, // e0 |
416 | | 0x010d, 0x00e9, 0x017a, 0x0117, 0x0123, 0x0137, 0x012b, 0x013c, // e8 |
417 | | 0x0161, 0x0144, 0x0146, 0x00f3, 0x014d, 0x00f5, 0x00f6, 0x00f7, // f0 |
418 | | 0x0173, 0x0142, 0x015b, 0x016b, 0x00fc, 0x017c, 0x017e, 0x2019, // f8 |
419 | | }; |
420 | | |
421 | | // Reference: http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-14.TXT |
422 | | static const uint16_t ISO_8859_14[0x80] = { |
423 | | 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, // 80 |
424 | | 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, // 88 |
425 | | 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, // 90 |
426 | | 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, // 98 |
427 | | 0x00a0, 0x1e02, 0x1e03, 0x00a3, 0x010a, 0x010b, 0x1e0a, 0x00a7, // a0 |
428 | | 0x1e80, 0x00a9, 0x1e82, 0x1e0b, 0x1ef2, 0x00ad, 0x00ae, 0x0178, // a8 |
429 | | 0x1e1e, 0x1e1f, 0x0120, 0x0121, 0x1e40, 0x1e41, 0x00b6, 0x1e56, // b0 |
430 | | 0x1e81, 0x1e57, 0x1e83, 0x1e60, 0x1ef3, 0x1e84, 0x1e85, 0x1e61, // b8 |
431 | | 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, // c0 |
432 | | 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8 |
433 | | 0x0174, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x1e6a, // d0 |
434 | | 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x0176, 0x00df, // d8 |
435 | | 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, // e0 |
436 | | 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8 |
437 | | 0x0175, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x1e6b, // f0 |
438 | | 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x0177, 0x00ff, // f8 |
439 | | }; |
440 | | |
441 | | // Reference: http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-15.TXT |
442 | | static const uint16_t ISO_8859_15[0x80] = { |
443 | | 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, // 80 |
444 | | 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, // 88 |
445 | | 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, // 90 |
446 | | 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, // 98 |
447 | | 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x20ac, 0x00a5, 0x0160, 0x00a7, // a0 |
448 | | 0x0161, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, // a8 |
449 | | 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x017d, 0x00b5, 0x00b6, 0x00b7, // b0 |
450 | | 0x017e, 0x00b9, 0x00ba, 0x00bb, 0x0152, 0x0153, 0x0178, 0x00bf, // b8 |
451 | | 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, // c0 |
452 | | 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8 |
453 | | 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, // d0 |
454 | | 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, // d8 |
455 | | 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, // e0 |
456 | | 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8 |
457 | | 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, // f0 |
458 | | 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff, // f8 |
459 | | }; |
460 | | |
461 | | // Reference: http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-16.TXT |
462 | | static const uint16_t ISO_8859_16[0x80] = { |
463 | | 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, // 80 |
464 | | 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, // 88 |
465 | | 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, // 90 |
466 | | 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, // 98 |
467 | | 0x00a0, 0x0104, 0x0105, 0x0141, 0x20ac, 0x201e, 0x0160, 0x00a7, // a0 |
468 | | 0x0161, 0x00a9, 0x0218, 0x00ab, 0x0179, 0x00ad, 0x017a, 0x017b, // a8 |
469 | | 0x00b0, 0x00b1, 0x010c, 0x0142, 0x017d, 0x201d, 0x00b6, 0x00b7, // b0 |
470 | | 0x017e, 0x010d, 0x0219, 0x00bb, 0x0152, 0x0153, 0x0178, 0x017c, // b8 |
471 | | 0x00c0, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0106, 0x00c6, 0x00c7, // c0 |
472 | | 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8 |
473 | | 0x0110, 0x0143, 0x00d2, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x015a, // d0 |
474 | | 0x0170, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x0118, 0x021a, 0x00df, // d8 |
475 | | 0x00e0, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x0107, 0x00e6, 0x00e7, // e0 |
476 | | 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8 |
477 | | 0x0111, 0x0144, 0x00f2, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x015b, // f0 |
478 | | 0x0171, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0119, 0x021b, 0x00ff, // f8 |
479 | | }; |
480 | | |
481 | | // Reference: http://www.iana.org/go/rfc1489 |
482 | | // Reference: http://www.unicode.org/Public/MAPPINGS/VENDORS/MISC/KOI8-R.TXT |
483 | | static const uint16_t KOI8_R[0x80] = { |
484 | | 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, // 80 |
485 | | 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, // 88 |
486 | | 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, // 90 |
487 | | 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, // 98 |
488 | | 0x00a0, 0x0104, 0x0105, 0x0141, 0x20ac, 0x201e, 0x0160, 0x00a7, // a0 |
489 | | 0x0161, 0x00a9, 0x0218, 0x00ab, 0x0179, 0x00ad, 0x017a, 0x017b, // a8 |
490 | | 0x00b0, 0x00b1, 0x010c, 0x0142, 0x017d, 0x201d, 0x00b6, 0x00b7, // b0 |
491 | | 0x017e, 0x010d, 0x0219, 0x00bb, 0x0152, 0x0153, 0x0178, 0x017c, // b8 |
492 | | 0x00c0, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0106, 0x00c6, 0x00c7, // c0 |
493 | | 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8 |
494 | | 0x0110, 0x0143, 0x00d2, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x015a, // d0 |
495 | | 0x0170, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x0118, 0x021a, 0x00df, // d8 |
496 | | 0x00e0, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x0107, 0x00e6, 0x00e7, // e0 |
497 | | 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8 |
498 | | 0x0111, 0x0144, 0x00f2, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x015b, // f0 |
499 | | 0x0171, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0119, 0x021b, 0x00ff, // f8 |
500 | | }; |
501 | | |
502 | | // Reference: http://varamozhi.sourceforge.net/iscii91.pdf |
503 | | static const uint16_t ISCII[0x80] = { |
504 | | 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // 80 |
505 | | 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // 88 |
506 | | 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // 90 |
507 | | 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // 98 |
508 | | 0xfffd, 0x0901, 0x0902, 0x0903, 0x0905, 0x0906, 0x0907, 0x0908, // a0 |
509 | | 0x0909, 0x090a, 0x090b, 0x090e, 0x090f, 0x0910, 0x090d, 0x0912, // a8 |
510 | | 0x0913, 0x0914, 0x0911, 0x0915, 0x0916, 0x0917, 0x0918, 0x0919, // b0 |
511 | | 0x091a, 0x091b, 0x091c, 0x091d, 0x091e, 0x091f, 0x0920, 0x0921, // b8 |
512 | | 0x0922, 0x0923, 0x0924, 0x0925, 0x0926, 0x0927, 0x0928, 0x0929, // c0 |
513 | | 0x092a, 0x092b, 0x092c, 0x092d, 0x092e, 0x092f, 0x095f, 0x0930, // c8 |
514 | | 0x0931, 0x0932, 0x0933, 0x0934, 0x0935, 0x0936, 0x0937, 0x0938, // d0 |
515 | | 0x0939, 0x0020, 0x093e, 0x093f, 0x0940, 0x0941, 0x0942, 0x0943, // d8 |
516 | | 0x0946, 0x0947, 0x0948, 0x0945, 0x094a, 0x094b, 0x094c, 0x0949, // e0 |
517 | | 0x094d, 0x093c, 0x0964, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // e8 |
518 | | 0x0020, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, // f0 |
519 | | 0x0037, 0x0038, 0x0039, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, // f8 |
520 | | }; |
521 | | |
522 | | static uint32_t |
523 | | string_decoder_getc_us_ascii(espeak_ng_TEXT_DECODER *decoder) |
524 | 0 | { |
525 | 0 | uint8_t c = *decoder->current++; |
526 | 0 | return (c >= 0x80) ? 0xFFFD : c; |
527 | 0 | } |
528 | | |
529 | | static uint32_t |
530 | | string_decoder_getc_codepage(espeak_ng_TEXT_DECODER *decoder) |
531 | 0 | { |
532 | 0 | uint8_t c = *decoder->current++; |
533 | 0 | return (c >= 0x80) ? decoder->codepage[c - 0x80] : c; |
534 | 0 | } |
535 | | |
536 | | static uint32_t |
537 | | string_decoder_getc_utf_8(espeak_ng_TEXT_DECODER *decoder) |
538 | 13.5M | { |
539 | 13.5M | uint8_t c = *decoder->current++; |
540 | 13.5M | uint32_t ret; |
541 | 13.5M | switch (c & 0xF0) |
542 | 13.5M | { |
543 | | // 1-byte UTF-8 sequence |
544 | 10.3M | case 0x00: case 0x10: case 0x20: case 0x30: |
545 | 12.6M | case 0x40: case 0x50: case 0x60: case 0x70: |
546 | 12.6M | return c; |
547 | | // UTF-8 tail byte -- invalid in isolation |
548 | 234k | case 0x80: case 0x90: case 0xA0: case 0xB0: |
549 | 234k | return 0xFFFD; |
550 | | // 2-byte UTF-8 sequence |
551 | 143k | case 0xC0: case 0xD0: |
552 | 143k | if (decoder->current + 1 >= decoder->end) goto eof; |
553 | 143k | ret = c & 0x1F; |
554 | 143k | if (((c = *decoder->current++) & LEADING_2_BITS) != UTF8_TAIL_BITS) goto error; |
555 | 46.4k | ret = (ret << 6) + (c & 0x3F); |
556 | 46.4k | return ret; |
557 | | // 3-byte UTF-8 sequence |
558 | 139k | case 0xE0: |
559 | 139k | if (decoder->current + 2 >= decoder->end) goto eof; |
560 | 138k | ret = c & 0x0F; |
561 | 138k | if (((c = *decoder->current++) & LEADING_2_BITS) != UTF8_TAIL_BITS) goto error; |
562 | 95.9k | ret = (ret << 6) + (c & 0x3F); |
563 | 95.9k | if (((c = *decoder->current++) & LEADING_2_BITS) != UTF8_TAIL_BITS) goto error; |
564 | 79.3k | ret = (ret << 6) + (c & 0x3F); |
565 | | // fix the "I umlaut a half" bug |
566 | 79.3k | if (ret == 0xFFFD) return 0x001A; |
567 | 79.2k | return ret; |
568 | | // 4-byte UTF-8 sequence |
569 | 403k | case 0xF0: |
570 | 403k | if (decoder->current + 3 >= decoder->end) goto eof; |
571 | 403k | ret = c & 0x0F; |
572 | 403k | if (((c = *decoder->current++) & LEADING_2_BITS) != UTF8_TAIL_BITS) goto error; |
573 | 55.7k | ret = (ret << 6) + (c & 0x3F); |
574 | 55.7k | if (((c = *decoder->current++) & LEADING_2_BITS) != UTF8_TAIL_BITS) goto error; |
575 | 44.1k | ret = (ret << 6) + (c & 0x3F); |
576 | 44.1k | if (((c = *decoder->current++) & LEADING_2_BITS) != UTF8_TAIL_BITS) goto error; |
577 | 36.5k | ret = (ret << 6) + (c & 0x3F); |
578 | 36.5k | return (ret <= 0x10FFFF) ? ret : 0xFFFD; |
579 | 13.5M | } |
580 | 524k | error: |
581 | 524k | --decoder->current; |
582 | 524k | return 0xFFFD; |
583 | 629 | eof: |
584 | 629 | decoder->current = decoder->end; |
585 | 629 | return 0xFFFD; |
586 | 13.5M | } |
587 | | |
588 | | static uint32_t |
589 | | string_decoder_getc_iso_10646_ucs_2(espeak_ng_TEXT_DECODER *decoder) |
590 | 0 | { |
591 | 0 | if (decoder->current + 1 >= decoder->end) { |
592 | 0 | decoder->current = decoder->end; |
593 | 0 | return 0xFFFD; |
594 | 0 | } |
595 | | |
596 | 0 | uint8_t c1 = *decoder->current++; |
597 | 0 | uint8_t c2 = *decoder->current++; |
598 | 0 | return c1 + (c2 << 8); |
599 | 0 | } |
600 | | |
601 | | static uint32_t |
602 | | string_decoder_getc_wchar(espeak_ng_TEXT_DECODER *decoder) |
603 | 0 | { |
604 | 0 | wchar_t c = *(const wchar_t *)decoder->current; |
605 | 0 | decoder->current += sizeof(wchar_t); |
606 | 0 | return c; |
607 | 0 | } |
608 | | |
609 | | static uint32_t |
610 | | string_decoder_getc_auto(espeak_ng_TEXT_DECODER *decoder) |
611 | 0 | { |
612 | 0 | const uint8_t *ptr = decoder->current; |
613 | 0 | uint32_t c = string_decoder_getc_utf_8(decoder); |
614 | 0 | if (c == 0xFFFD) { |
615 | 0 | decoder->get = string_decoder_getc_codepage; |
616 | 0 | decoder->current = ptr; |
617 | 0 | c = decoder->get(decoder); |
618 | 0 | } |
619 | 0 | return c; |
620 | 0 | } |
621 | | |
622 | | static uint32_t |
623 | | null_decoder_getc(espeak_ng_TEXT_DECODER *decoder) |
624 | 0 | { |
625 | 0 | (void)decoder; // unused parameter |
626 | 0 | return 0; |
627 | 0 | } |
628 | | |
629 | | typedef struct |
630 | | { |
631 | | uint32_t (*get)(espeak_ng_TEXT_DECODER *decoder); |
632 | | const uint16_t *codepage; |
633 | | } encoding_t; |
634 | | |
635 | | static const encoding_t string_decoders[] = { |
636 | | { NULL, NULL }, |
637 | | { string_decoder_getc_us_ascii, NULL }, |
638 | | { string_decoder_getc_codepage, ISO_8859_1 }, |
639 | | { string_decoder_getc_codepage, ISO_8859_2 }, |
640 | | { string_decoder_getc_codepage, ISO_8859_3 }, |
641 | | { string_decoder_getc_codepage, ISO_8859_4 }, |
642 | | { string_decoder_getc_codepage, ISO_8859_5 }, |
643 | | { string_decoder_getc_codepage, ISO_8859_6 }, |
644 | | { string_decoder_getc_codepage, ISO_8859_7 }, |
645 | | { string_decoder_getc_codepage, ISO_8859_8 }, |
646 | | { string_decoder_getc_codepage, ISO_8859_9 }, |
647 | | { string_decoder_getc_codepage, ISO_8859_10 }, |
648 | | { string_decoder_getc_codepage, ISO_8859_11 }, |
649 | | // ISO-8859-12 is not a valid encoding. |
650 | | { string_decoder_getc_codepage, ISO_8859_13 }, |
651 | | { string_decoder_getc_codepage, ISO_8859_14 }, |
652 | | { string_decoder_getc_codepage, ISO_8859_15 }, |
653 | | { string_decoder_getc_codepage, ISO_8859_16 }, |
654 | | { string_decoder_getc_codepage, KOI8_R }, |
655 | | { string_decoder_getc_codepage, ISCII }, |
656 | | { string_decoder_getc_utf_8, NULL }, |
657 | | { string_decoder_getc_iso_10646_ucs_2, NULL }, |
658 | | }; |
659 | | |
660 | | #pragma GCC visibility push(default) |
661 | | |
662 | | espeak_ng_TEXT_DECODER * |
663 | | create_text_decoder(void) |
664 | 1 | { |
665 | 1 | espeak_ng_TEXT_DECODER *decoder = malloc(sizeof(espeak_ng_TEXT_DECODER)); |
666 | 1 | if (!decoder) return NULL; |
667 | | |
668 | 1 | decoder->current = NULL; |
669 | 1 | decoder->end = NULL; |
670 | 1 | decoder->get = NULL; |
671 | 1 | decoder->codepage = NULL; |
672 | 1 | return decoder; |
673 | 1 | } |
674 | | |
675 | | void |
676 | | destroy_text_decoder(espeak_ng_TEXT_DECODER *decoder) |
677 | 0 | { |
678 | 0 | if (decoder) free(decoder); |
679 | 0 | } |
680 | | |
681 | | espeak_ng_STATUS |
682 | | text_decoder_decode_string(espeak_ng_TEXT_DECODER *decoder, |
683 | | const char *string, |
684 | | int length, |
685 | | espeak_ng_ENCODING encoding) |
686 | 2.86k | { |
687 | 2.86k | if (encoding > ESPEAKNG_ENCODING_ISO_10646_UCS_2) |
688 | 0 | return ENS_UNKNOWN_TEXT_ENCODING; |
689 | | |
690 | 2.86k | const encoding_t *enc = string_decoders + encoding; |
691 | 2.86k | if (enc->get == NULL) |
692 | 0 | return ENS_UNKNOWN_TEXT_ENCODING; |
693 | | |
694 | 2.86k | if (length < 0) length = string ? strlen(string) + 1 : 0; |
695 | | |
696 | 2.86k | decoder->get = string ? enc->get : null_decoder_getc; |
697 | 2.86k | decoder->codepage = enc->codepage; |
698 | 2.86k | decoder->current = (const uint8_t *)string; |
699 | 2.86k | decoder->end = (const uint8_t *)(string ? string + length : string); |
700 | 2.86k | return ENS_OK; |
701 | 2.86k | } |
702 | | |
703 | | espeak_ng_STATUS |
704 | | text_decoder_decode_string_auto(espeak_ng_TEXT_DECODER *decoder, |
705 | | const char *string, |
706 | | int length, |
707 | | espeak_ng_ENCODING encoding) |
708 | 0 | { |
709 | 0 | if (encoding > ESPEAKNG_ENCODING_ISO_10646_UCS_2) |
710 | 0 | return ENS_UNKNOWN_TEXT_ENCODING; |
711 | | |
712 | 0 | const encoding_t *enc = string_decoders + encoding; |
713 | 0 | if (enc->get == NULL) |
714 | 0 | return ENS_UNKNOWN_TEXT_ENCODING; |
715 | | |
716 | 0 | if (length < 0) length = string ? strlen(string) + 1 : 0; |
717 | |
|
718 | 0 | decoder->get = string ? string_decoder_getc_auto : null_decoder_getc; |
719 | 0 | decoder->codepage = enc->codepage; |
720 | 0 | decoder->current = (const uint8_t *)string; |
721 | 0 | decoder->end = (const uint8_t *)(string ? string + length : string); |
722 | 0 | return ENS_OK; |
723 | 0 | } |
724 | | |
725 | | espeak_ng_STATUS |
726 | | text_decoder_decode_wstring(espeak_ng_TEXT_DECODER *decoder, |
727 | | const wchar_t *string, |
728 | | int length) |
729 | 0 | { |
730 | 0 | if (length < 0) length = string ? wcslen(string) + 1 : 0; |
731 | |
|
732 | 0 | decoder->get = string ? string_decoder_getc_wchar : null_decoder_getc; |
733 | 0 | decoder->codepage = NULL; |
734 | 0 | decoder->current = (const uint8_t *)string; |
735 | 0 | decoder->end = (const uint8_t *)(string ? string + length : string); |
736 | 0 | return ENS_OK; |
737 | 0 | } |
738 | | |
739 | | espeak_ng_STATUS |
740 | | text_decoder_decode_string_multibyte(espeak_ng_TEXT_DECODER *decoder, |
741 | | const void *input, |
742 | | espeak_ng_ENCODING encoding, |
743 | | int flags) |
744 | 2.86k | { |
745 | 2.86k | switch (flags & 7) |
746 | 2.86k | { |
747 | 0 | case espeakCHARS_WCHAR: |
748 | 0 | return text_decoder_decode_wstring(decoder, (const wchar_t *)input, -1); |
749 | 0 | case espeakCHARS_AUTO: |
750 | 0 | return text_decoder_decode_string_auto(decoder, (const char *)input, -1, encoding); |
751 | 2.86k | case espeakCHARS_UTF8: |
752 | 2.86k | return text_decoder_decode_string(decoder, (const char *)input, -1, ESPEAKNG_ENCODING_UTF_8); |
753 | 0 | case espeakCHARS_8BIT: |
754 | 0 | return text_decoder_decode_string(decoder, (const char *)input, -1, encoding); |
755 | 0 | case espeakCHARS_16BIT: |
756 | 0 | return text_decoder_decode_string(decoder, (const char *)input, -1, ESPEAKNG_ENCODING_ISO_10646_UCS_2); |
757 | 0 | default: |
758 | 0 | return ENS_UNKNOWN_TEXT_ENCODING; |
759 | 2.86k | } |
760 | 2.86k | } |
761 | | |
762 | | int |
763 | | text_decoder_eof(espeak_ng_TEXT_DECODER *decoder) |
764 | 18.2M | { |
765 | 18.2M | return decoder->current == decoder->end; |
766 | 18.2M | } |
767 | | |
768 | | uint32_t |
769 | | text_decoder_getc(espeak_ng_TEXT_DECODER *decoder) |
770 | 13.5M | { |
771 | 13.5M | return decoder->get(decoder); |
772 | 13.5M | } |
773 | | |
774 | | uint32_t |
775 | | text_decoder_peekc(espeak_ng_TEXT_DECODER *decoder) |
776 | 2.19k | { |
777 | 2.19k | if (decoder->current == decoder->end) return 0; |
778 | | |
779 | 2.19k | const uint8_t *current = decoder->current; |
780 | 2.19k | uint32_t c = decoder->get(decoder); |
781 | 2.19k | decoder->current = current; |
782 | 2.19k | return c; |
783 | 2.19k | } |
784 | | |
785 | | const void * |
786 | | text_decoder_get_buffer(espeak_ng_TEXT_DECODER *decoder) |
787 | 0 | { |
788 | 0 | if (text_decoder_eof(decoder)) |
789 | 0 | return NULL; |
790 | 0 | return decoder->current; |
791 | 0 | } |
792 | | |
793 | | #pragma GCC visibility pop |