ObjFW  Check-in [2c489201b7]

Overview
Comment:Add KOI8-U encoding
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2c489201b7f3162784fe26de3e8950f3eac347430163509d97d74ef44480aaf7
User & Date: js on 2017-02-05 21:22:55
Other Links: manifest | tags
Context
2017-02-05
22:47
Add ISO-8859-3 check-in: 52e6e8aa89 user: js tags: trunk
21:22
Add KOI8-U encoding check-in: 2c489201b7 user: js tags: trunk
01:31
Add KOI8-R encoding check-in: 59348cd51d user: js tags: trunk
Changes

Modified configure.ac from [8493d1aa1e] to [dd01c03aba].

611
612
613
614
615
616
617

618
619
620
621
622
623
624
])
ENCODING_FLAG(codepage-437, codepage_437, [Codepage 437], HAVE_CODEPAGE_437)
ENCODING_FLAG(codepage-850, codepage_850, [Codepage 850], HAVE_CODEPAGE_850)
ENCODING_FLAG(codepage-858, codepage_858, [Codepage 858], HAVE_CODEPAGE_858)
ENCODING_FLAG(iso-8859-2, iso_8859_2, [ISO 8859-2], HAVE_ISO_8859_2)
ENCODING_FLAG(iso-8859-15, iso_8859_15, [ISO 8859-15], HAVE_ISO_8859_15)
ENCODING_FLAG(koi8-r, koi8_r, [KOI8-R], HAVE_KOI8_R)

ENCODING_FLAG(mac-roman, mac_roman, [Mac Roman encoding], HAVE_MAC_ROMAN)
ENCODING_FLAG(windows-1251, windows_1251, [Windows-1251], HAVE_WINDOWS_1251)
ENCODING_FLAG(windows-1252, windows_1252, [Windows-1252], HAVE_WINDOWS_1252)

AC_SUBST(ENCODINGS_SRCS)
AS_IF([test x"$ENCODINGS_SRCS" != x""], [
	AC_SUBST(ENCODINGS, "encodings")







>







611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
])
ENCODING_FLAG(codepage-437, codepage_437, [Codepage 437], HAVE_CODEPAGE_437)
ENCODING_FLAG(codepage-850, codepage_850, [Codepage 850], HAVE_CODEPAGE_850)
ENCODING_FLAG(codepage-858, codepage_858, [Codepage 858], HAVE_CODEPAGE_858)
ENCODING_FLAG(iso-8859-2, iso_8859_2, [ISO 8859-2], HAVE_ISO_8859_2)
ENCODING_FLAG(iso-8859-15, iso_8859_15, [ISO 8859-15], HAVE_ISO_8859_15)
ENCODING_FLAG(koi8-r, koi8_r, [KOI8-R], HAVE_KOI8_R)
ENCODING_FLAG(koi8-u, koi8_u, [KOI8-U], HAVE_KOI8_U)
ENCODING_FLAG(mac-roman, mac_roman, [Mac Roman encoding], HAVE_MAC_ROMAN)
ENCODING_FLAG(windows-1251, windows_1251, [Windows-1251], HAVE_WINDOWS_1251)
ENCODING_FLAG(windows-1252, windows_1252, [Windows-1252], HAVE_WINDOWS_1252)

AC_SUBST(ENCODINGS_SRCS)
AS_IF([test x"$ENCODINGS_SRCS" != x""], [
	AC_SUBST(ENCODINGS, "encodings")

Modified src/OFString.h from [7404ad4f5f] to [29d3db12c3].

72
73
74
75
76
77
78


79
80
81
82
83
84
85
	OF_STRING_ENCODING_CODEPAGE_850,
	/*! Codepage 858 */
	OF_STRING_ENCODING_CODEPAGE_858,
	/*! Mac OS Roman */
	OF_STRING_ENCODING_MAC_ROMAN,
	/*! KOI8-R */
	OF_STRING_ENCODING_KOI8_R,


	/*! Try to automatically detect the encoding */
	OF_STRING_ENCODING_AUTODETECT = 0xFF
} of_string_encoding_t;

enum {
	OF_STRING_SEARCH_BACKWARDS = 1,
	OF_STRING_SKIP_EMPTY	   = 2







>
>







72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
	OF_STRING_ENCODING_CODEPAGE_850,
	/*! Codepage 858 */
	OF_STRING_ENCODING_CODEPAGE_858,
	/*! Mac OS Roman */
	OF_STRING_ENCODING_MAC_ROMAN,
	/*! KOI8-R */
	OF_STRING_ENCODING_KOI8_R,
	/*! KOI8-U */
	OF_STRING_ENCODING_KOI8_U,
	/*! Try to automatically detect the encoding */
	OF_STRING_ENCODING_AUTODETECT = 0xFF
} of_string_encoding_t;

enum {
	OF_STRING_SEARCH_BACKWARDS = 1,
	OF_STRING_SKIP_EMPTY	   = 2

Modified src/OFString.m from [5396444804] to [318583ea01].

103
104
105
106
107
108
109


110
111
112
113
114
115
116
    size_t, bool);
extern bool of_unicode_to_codepage_858(const of_unichar_t*, unsigned char*,
    size_t, bool);
extern bool of_unicode_to_mac_roman(const of_unichar_t*, unsigned char*,
    size_t, bool);
extern bool of_unicode_to_koi8_r(const of_unichar_t*, unsigned char*,
    size_t, bool);



/* References for static linking */
void
_references_to_categories_of_OFString(void)
{
	_OFString_CryptoHashing_reference = 1;
	_OFString_JSONValue_reference = 1;







>
>







103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
    size_t, bool);
extern bool of_unicode_to_codepage_858(const of_unichar_t*, unsigned char*,
    size_t, bool);
extern bool of_unicode_to_mac_roman(const of_unichar_t*, unsigned char*,
    size_t, bool);
extern bool of_unicode_to_koi8_r(const of_unichar_t*, unsigned char*,
    size_t, bool);
extern bool of_unicode_to_koi8_u(const of_unichar_t*, unsigned char*,
    size_t, bool);

/* References for static linking */
void
_references_to_categories_of_OFString(void)
{
	_OFString_CryptoHashing_reference = 1;
	_OFString_JSONValue_reference = 1;
164
165
166
167
168
169
170


171
172
173
174
175
176
177
	else if ([string isEqual: @"cp858"] || [string isEqual: @"cp-858"] ||
	    [string isEqual: @"ibm858"] || [string isEqual: @"858"])
		encoding = OF_STRING_ENCODING_CODEPAGE_858;
	else if ([string isEqual: @"macintosh"] || [string isEqual: @"mac"])
		encoding = OF_STRING_ENCODING_MAC_ROMAN;
	else if ([string isEqual: @"koi8-r"])
		encoding = OF_STRING_ENCODING_KOI8_R;


	else
		@throw [OFInvalidEncodingException exception];

	objc_autoreleasePoolPop(pool);

	return encoding;
}







>
>







166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
	else if ([string isEqual: @"cp858"] || [string isEqual: @"cp-858"] ||
	    [string isEqual: @"ibm858"] || [string isEqual: @"858"])
		encoding = OF_STRING_ENCODING_CODEPAGE_858;
	else if ([string isEqual: @"macintosh"] || [string isEqual: @"mac"])
		encoding = OF_STRING_ENCODING_MAC_ROMAN;
	else if ([string isEqual: @"koi8-r"])
		encoding = OF_STRING_ENCODING_KOI8_R;
	else if ([string isEqual: @"koi8-u"])
		encoding = OF_STRING_ENCODING_KOI8_U;
	else
		@throw [OFInvalidEncodingException exception];

	objc_autoreleasePoolPop(pool);

	return encoding;
}
1232
1233
1234
1235
1236
1237
1238













1239
1240
1241
1242
1243
1244
1245
		    (unsigned char*)cString, length, lossy))
			@throw [OFInvalidEncodingException exception];

		cString[length] = '\0';

		return length;
#endif













	default:
		@throw [OFNotImplementedException exceptionWithSelector: _cmd
								 object: self];
	}
}

- (size_t)getCString: (char*)cString







>
>
>
>
>
>
>
>
>
>
>
>
>







1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
		    (unsigned char*)cString, length, lossy))
			@throw [OFInvalidEncodingException exception];

		cString[length] = '\0';

		return length;
#endif
#ifdef HAVE_KOI8_U
	case OF_STRING_ENCODING_KOI8_U:
		if (length + 1 > maxLength)
			@throw [OFOutOfRangeException exception];

		if (!of_unicode_to_koi8_u(characters,
		    (unsigned char*)cString, length, lossy))
			@throw [OFInvalidEncodingException exception];

		cString[length] = '\0';

		return length;
#endif
	default:
		@throw [OFNotImplementedException exceptionWithSelector: _cmd
								 object: self];
	}
}

- (size_t)getCString: (char*)cString
1295
1296
1297
1298
1299
1300
1301

1302
1303
1304
1305
1306
1307
1308
	case OF_STRING_ENCODING_WINDOWS_1251:
	case OF_STRING_ENCODING_WINDOWS_1252:
	case OF_STRING_ENCODING_CODEPAGE_437:
	case OF_STRING_ENCODING_CODEPAGE_850:
	case OF_STRING_ENCODING_CODEPAGE_858:
	case OF_STRING_ENCODING_MAC_ROMAN:
	case OF_STRING_ENCODING_KOI8_R:

		cString = [object allocMemoryWithSize: length + 1];

		[self OF_getCString: cString
			  maxLength: length + 1
			   encoding: encoding
			      lossy: lossy];








>







1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
	case OF_STRING_ENCODING_WINDOWS_1251:
	case OF_STRING_ENCODING_WINDOWS_1252:
	case OF_STRING_ENCODING_CODEPAGE_437:
	case OF_STRING_ENCODING_CODEPAGE_850:
	case OF_STRING_ENCODING_CODEPAGE_858:
	case OF_STRING_ENCODING_MAC_ROMAN:
	case OF_STRING_ENCODING_KOI8_R:
	case OF_STRING_ENCODING_KOI8_U:
		cString = [object allocMemoryWithSize: length + 1];

		[self OF_getCString: cString
			  maxLength: length + 1
			   encoding: encoding
			      lossy: lossy];

1365
1366
1367
1368
1369
1370
1371

1372
1373
1374
1375
1376
1377
1378
	case OF_STRING_ENCODING_WINDOWS_1251:
	case OF_STRING_ENCODING_WINDOWS_1252:
	case OF_STRING_ENCODING_CODEPAGE_437:
	case OF_STRING_ENCODING_CODEPAGE_850:
	case OF_STRING_ENCODING_CODEPAGE_858:
	case OF_STRING_ENCODING_MAC_ROMAN:
	case OF_STRING_ENCODING_KOI8_R:

		return [self length];
	default:
		@throw [OFInvalidEncodingException exception];
	}
}

- (size_t)UTF8StringLength







>







1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
	case OF_STRING_ENCODING_WINDOWS_1251:
	case OF_STRING_ENCODING_WINDOWS_1252:
	case OF_STRING_ENCODING_CODEPAGE_437:
	case OF_STRING_ENCODING_CODEPAGE_850:
	case OF_STRING_ENCODING_CODEPAGE_858:
	case OF_STRING_ENCODING_MAC_ROMAN:
	case OF_STRING_ENCODING_KOI8_R:
	case OF_STRING_ENCODING_KOI8_U:
		return [self length];
	default:
		@throw [OFInvalidEncodingException exception];
	}
}

- (size_t)UTF8StringLength

Modified src/OFString_UTF8.m from [7036f0659c] to [37fcb522a7].

43
44
45
46
47
48
49

50
51
52
53
54
55
56
extern const of_char16_t of_windows_1251[128];
extern const of_char16_t of_windows_1252[128];
extern const of_char16_t of_codepage_437[128];
extern const of_char16_t of_codepage_850[128];
extern const of_char16_t of_codepage_858[128];
extern const of_char16_t of_mac_roman[128];
extern const of_char16_t of_koi8_r[128];


static inline int
memcasecmp(const char *first, const char *second, size_t length)
{
	for (size_t i = 0; i < length; i++) {
		unsigned char f = first[i];
		unsigned char s = second[i];







>







43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
extern const of_char16_t of_windows_1251[128];
extern const of_char16_t of_windows_1252[128];
extern const of_char16_t of_codepage_437[128];
extern const of_char16_t of_codepage_850[128];
extern const of_char16_t of_codepage_858[128];
extern const of_char16_t of_mac_roman[128];
extern const of_char16_t of_koi8_r[128];
extern const of_char16_t of_koi8_u[128];

static inline int
memcasecmp(const char *first, const char *second, size_t length)
{
	for (size_t i = 0; i < length; i++) {
		unsigned char f = first[i];
		unsigned char s = second[i];
332
333
334
335
336
337
338





339
340
341
342
343
344
345
			table = of_mac_roman;
			break;
#endif
#ifdef HAVE_KOI8_R
		case OF_STRING_ENCODING_KOI8_R:
			table = of_koi8_r;
			break;





#endif
		default:
			@throw [OFInvalidEncodingException exception];
		}

		j = 0;
		for (size_t i = 0; i < cStringLength; i++) {







>
>
>
>
>







333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
			table = of_mac_roman;
			break;
#endif
#ifdef HAVE_KOI8_R
		case OF_STRING_ENCODING_KOI8_R:
			table = of_koi8_r;
			break;
#endif
#ifdef HAVE_KOI8_U
		case OF_STRING_ENCODING_KOI8_U:
			table = of_koi8_u;
			break;
#endif
		default:
			@throw [OFInvalidEncodingException exception];
		}

		j = 0;
		for (size_t i = 0; i < cStringLength; i++) {

Added src/encodings/koi8_u.m version [2867893b70].

























































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
 *   Jonathan Schleifer <js@heap.zone>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "OFString.h"

const of_char16_t of_koi8_u[128] = {
	0x2500, 0x2502, 0x250C, 0x2510, 0x2514, 0x2518, 0x251C, 0x2524,
	0x252C, 0x2534, 0x253C, 0x2580, 0x2584, 0x2588, 0x258C, 0x2590,
	0x2591, 0x2592, 0x2593, 0x2320, 0x25A0, 0x2219, 0x221A, 0x2248,
	0x2264,	0x2265, 0x00A0, 0x2321, 0x00B0, 0x00B2, 0x00B7, 0x00F7,
	0x2550, 0x2551, 0x2552, 0x0451, 0x0454, 0x2554, 0x0456, 0x0457,
	0x2557, 0x2558, 0x2559, 0x255A, 0x255B, 0x0491, 0x255D, 0x255E,
	0x255F, 0x2560, 0x2561, 0x0401, 0x0404, 0x2563, 0x0406, 0x0407,
	0x2566, 0x2567, 0x2568, 0x2569, 0x256A, 0x0490, 0x256C, 0x00A9,
	0x044E, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433,
	0x0445, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E,
	0x043F, 0x044F, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432,
	0x044C, 0x044B, 0x0437, 0x0448, 0x044D, 0x0449, 0x0447, 0x044A,
	0x042E, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413,
	0x0425, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E,
	0x041F, 0x042F, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412,
	0x042C, 0x042B, 0x0417, 0x0428, 0x042D, 0x0429, 0x0427, 0x042A
};

bool
of_unicode_to_koi8_u(const of_unichar_t *input, unsigned char *output,
    size_t length, bool lossy)
{
	for (size_t i = 0; i < length; i++) {
		of_unichar_t c = input[i];

		if OF_UNLIKELY (c > 0x7F) {
			if OF_UNLIKELY (c > 0xFFFF) {
				if (lossy) {
					output[i] = '?';
					continue;
				} else
					return false;
			}

			if OF_LIKELY (c >= 0x438 && c <= 0x43F)
				output[i] = 0xC9 + (c - 0x438);
			else if OF_LIKELY (c >= 0x418 && c <= 0x41F)
				output[i] = 0xE9 + (c - 0x418);
			else {
				switch ((of_char16_t)c) {
				case 0x2500:
					output[i] = 0x80;
					break;
				case 0x2502:
					output[i] = 0x81;
					break;
				case 0x250C:
					output[i] = 0x82;
					break;
				case 0x2510:
					output[i] = 0x83;
					break;
				case 0x2514:
					output[i] = 0x84;
					break;
				case 0x2518:
					output[i] = 0x85;
					break;
				case 0x251C:
					output[i] = 0x86;
					break;
				case 0x2524:
					output[i] = 0x87;
					break;
				case 0x252C:
					output[i] = 0x88;
					break;
				case 0x2534:
					output[i] = 0x89;
					break;
				case 0x253C:
					output[i] = 0x8A;
					break;
				case 0x2580:
					output[i] = 0x8B;
					break;
				case 0x2584:
					output[i] = 0x8C;
					break;
				case 0x2588:
					output[i] = 0x8D;
					break;
				case 0x258C:
					output[i] = 0x8E;
					break;
				case 0x2590:
					output[i] = 0x8F;
					break;
				case 0x2591:
					output[i] = 0x90;
					break;
				case 0x2592:
					output[i] = 0x91;
					break;
				case 0x2593:
					output[i] = 0x92;
					break;
				case 0x2320:
					output[i] = 0x93;
					break;
				case 0x25A0:
					output[i] = 0x94;
					break;
				case 0x2219:
					output[i] = 0x95;
					break;
				case 0x221A:
					output[i] = 0x96;
					break;
				case 0x2248:
					output[i] = 0x97;
					break;
				case 0x2264:
					output[i] = 0x98;
					break;
				case 0x2265:
					output[i] = 0x99;
					break;
				case 0xA0:
					output[i] = 0x9A;
					break;
				case 0x2321:
					output[i] = 0x9B;
					break;
				case 0xB0:
					output[i] = 0x9C;
					break;
				case 0xB2:
					output[i] = 0x9D;
					break;
				case 0xB7:
					output[i] = 0x9E;
					break;
				case 0xF7:
					output[i] = 0x9F;
					break;
				case 0x2550:
					output[i] = 0xA0;
					break;
				case 0x2551:
					output[i] = 0xA1;
					break;
				case 0x2552:
					output[i] = 0xA2;
					break;
				case 0x451:
					output[i] = 0xA3;
					break;
				case 0x454:
					output[i] = 0xA4;
					break;
				case 0x2554:
					output[i] = 0xA5;
					break;
				case 0x456:
					output[i] = 0xA6;
					break;
				case 0x457:
					output[i] = 0xA7;
					break;
				case 0x2557:
					output[i] = 0xA8;
					break;
				case 0x2558:
					output[i] = 0xA9;
					break;
				case 0x2559:
					output[i] = 0xAA;
					break;
				case 0x255A:
					output[i] = 0xAB;
					break;
				case 0x255B:
					output[i] = 0xAC;
					break;
				case 0x491:
					output[i] = 0xAD;
					break;
				case 0x255D:
					output[i] = 0xAE;
					break;
				case 0x255E:
					output[i] = 0xAF;
					break;
				case 0x255F:
					output[i] = 0xB0;
					break;
				case 0x2560:
					output[i] = 0xB1;
					break;
				case 0x2561:
					output[i] = 0xB2;
					break;
				case 0x401:
					output[i] = 0xB3;
					break;
				case 0x404:
					output[i] = 0xB4;
					break;
				case 0x2563:
					output[i] = 0xB5;
					break;
				case 0x406:
					output[i] = 0xB6;
					break;
				case 0x407:
					output[i] = 0xB7;
					break;
				case 0x2566:
					output[i] = 0xB8;
					break;
				case 0x2567:
					output[i] = 0xB9;
					break;
				case 0x2568:
					output[i] = 0xBA;
					break;
				case 0x2569:
					output[i] = 0xBB;
					break;
				case 0x256A:
					output[i] = 0xBC;
					break;
				case 0x490:
					output[i] = 0xBD;
					break;
				case 0x256C:
					output[i] = 0xBE;
					break;
				case 0xA9:
					output[i] = 0xBF;
					break;
				case 0x44E:
					output[i] = 0xC0;
					break;
				case 0x430:
					output[i] = 0xC1;
					break;
				case 0x431:
					output[i] = 0xC2;
					break;
				case 0x446:
					output[i] = 0xC3;
					break;
				case 0x434:
					output[i] = 0xC4;
					break;
				case 0x435:
					output[i] = 0xC5;
					break;
				case 0x444:
					output[i] = 0xC6;
					break;
				case 0x433:
					output[i] = 0xC7;
					break;
				case 0x445:
					output[i] = 0xC8;
					break;
				case 0x44F:
					output[i] = 0xD1;
					break;
				case 0x440:
					output[i] = 0xD2;
					break;
				case 0x441:
					output[i] = 0xD3;
					break;
				case 0x442:
					output[i] = 0xD4;
					break;
				case 0x443:
					output[i] = 0xD5;
					break;
				case 0x436:
					output[i] = 0xD6;
					break;
				case 0x432:
					output[i] = 0xD7;
					break;
				case 0x44C:
					output[i] = 0xD8;
					break;
				case 0x44B:
					output[i] = 0xD9;
					break;
				case 0x437:
					output[i] = 0xDA;
					break;
				case 0x448:
					output[i] = 0xDB;
					break;
				case 0x44D:
					output[i] = 0xDC;
					break;
				case 0x449:
					output[i] = 0xDD;
					break;
				case 0x447:
					output[i] = 0xDE;
					break;
				case 0x44A:
					output[i] = 0xDF;
					break;
				case 0x42E:
					output[i] = 0xE0;
					break;
				case 0x410:
					output[i] = 0xE1;
					break;
				case 0x411:
					output[i] = 0xE2;
					break;
				case 0x426:
					output[i] = 0xE3;
					break;
				case 0x414:
					output[i] = 0xE4;
					break;
				case 0x415:
					output[i] = 0xE5;
					break;
				case 0x424:
					output[i] = 0xE6;
					break;
				case 0x413:
					output[i] = 0xE7;
					break;
				case 0x425:
					output[i] = 0xE8;
					break;
				case 0x42F:
					output[i] = 0xF1;
					break;
				case 0x420:
					output[i] = 0xF2;
					break;
				case 0x421:
					output[i] = 0xF3;
					break;
				case 0x422:
					output[i] = 0xF4;
					break;
				case 0x423:
					output[i] = 0xF5;
					break;
				case 0x416:
					output[i] = 0xF6;
					break;
				case 0x412:
					output[i] = 0xF7;
					break;
				case 0x42C:
					output[i] = 0xF8;
					break;
				case 0x42B:
					output[i] = 0xF9;
					break;
				case 0x417:
					output[i] = 0xFA;
					break;
				case 0x428:
					output[i] = 0xFB;
					break;
				case 0x42D:
					output[i] = 0xFC;
					break;
				case 0x429:
					output[i] = 0xFD;
					break;
				case 0x427:
					output[i] = 0xFE;
					break;
				case 0x42A:
					output[i] = 0xFF;
					break;
				default:
					if (lossy)
						output[i] = '?';
					else
						return false;

					break;
				}
			}
		} else
			output[i] = (unsigned char)c;
	}

	return true;
}