ObjFW  Check-in [a1bcdc2ff6]

Overview
Comment:Move Unicode -> * conversions to separate files.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a1bcdc2ff686df5c40d4d6521b8b59623979441dbb395044a829743f8acddb85
User & Date: js on 2014-01-17 16:41:31
Other Links: manifest | tags
Context
2014-01-18
15:22
apple-forwarding-ppc: Fix unknown section warning. check-in: d09f4b94f3 user: js tags: trunk
2014-01-17
16:41
Move Unicode -> * conversions to separate files. check-in: a1bcdc2ff6 user: js tags: trunk
03:12
Add -[OFString lossyCStringWithEncoding:]. check-in: 1b0a5cf829 user: js tags: trunk
Changes

Modified src/OFString.m from [48162efaaf] to [17a63459d4].

70
71
72
73
74
75
76




77
78
79
80
81
82
83
- (size_t)OF_getCString: (char*)cString
	      maxLength: (size_t)maxLength
	       encoding: (of_string_encoding_t)encoding
		  lossy: (bool)lossy;
- (const char*)OF_cStringWithEncoding: (of_string_encoding_t)encoding
				lossy: (bool)lossy;
@end





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







>
>
>
>







70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
- (size_t)OF_getCString: (char*)cString
	      maxLength: (size_t)maxLength
	       encoding: (of_string_encoding_t)encoding
		  lossy: (bool)lossy;
- (const char*)OF_cStringWithEncoding: (of_string_encoding_t)encoding
				lossy: (bool)lossy;
@end

extern bool of_unicode_to_iso_8859_15(const of_unichar_t*, char*, size_t, bool);
extern bool of_unicode_to_windows_1252(const of_unichar_t*, char*, size_t,
    bool);

/* References for static linking */
void _references_to_categories_of_OFString(void)
{
	_OFString_Hashing_reference = 1;
	_OFString_JSONValue_reference = 1;
	_OFString_Serialization_reference = 1;
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
		cString[i] = '\0';

		return length;
	case OF_STRING_ENCODING_ISO_8859_15:
		if (length + 1 > maxLength)
			@throw [OFOutOfRangeException exception];

		for (i = 0; i < length; i++) {
			of_unichar_t c = characters[i];

			switch (c) {
			case 0xA4:
			case 0xA6:
			case 0xA8:
			case 0xB4:
			case 0xB8:
			case 0xBC:
			case 0xBD:
			case 0xBE:
				if (lossy)
					cString[i] = '?';
				else
					@throw [OFInvalidEncodingException
					    exception];

				break;
			}

			if OF_UNLIKELY (c > 0xFF) {
				switch (c) {
				case 0x20AC:
					cString[i] = 0xA4;
					break;
				case 0x160:
					cString[i] = 0xA6;
					break;
				case 0x161:
					cString[i] = 0xA8;
					break;
				case 0x17D:
					cString[i] = 0xB4;
					break;
				case 0x17E:
					cString[i] = 0xB8;
					break;
				case 0x152:
					cString[i] = 0xBC;
					break;
				case 0x153:
					cString[i] = 0xBD;
					break;
				case 0x178:
					cString[i] = 0xBE;
					break;
				default:
					if (lossy)
						cString[i] = '?';
					else
						@throw
						    [OFInvalidEncodingException
						    exception];

					break;
				}
			} else
				cString[i] = (uint8_t)c;
		}

		cString[i] = '\0';

		return length;
	case OF_STRING_ENCODING_WINDOWS_1252:
		if (length + 1 > maxLength)
			@throw [OFOutOfRangeException exception];

		for (i = 0; i < length; i++) {
			of_unichar_t c = characters[i];

			if OF_UNLIKELY (c >= 0x80 && c <= 0x9F) {
				if (lossy)
					cString[i] = '?';
				else
					@throw [OFInvalidEncodingException
					    exception];
			}

			if OF_UNLIKELY (c > 0xFF) {
				switch (c) {
				case 0x20AC:
					cString[i] = 0x80;
					break;
				case 0x201A:
					cString[i] = 0x82;
					break;
				case 0x192:
					cString[i] = 0x83;
					break;
				case 0x201E:
					cString[i] = 0x84;
					break;
				case 0x2026:
					cString[i] = 0x85;
					break;
				case 0x2020:
					cString[i] = 0x86;
					break;
				case 0x2021:
					cString[i] = 0x87;
					break;
				case 0x2C6:
					cString[i] = 0x88;
					break;
				case 0x2030:
					cString[i] = 0x89;
					break;
				case 0x160:
					cString[i] = 0x8A;
					break;
				case 0x2039:
					cString[i] = 0x8B;
					break;
				case 0x152:
					cString[i] = 0x8C;
					break;
				case 0x17D:
					cString[i] = 0x8E;
					break;
				case 0x2018:
					cString[i] = 0x91;
					break;
				case 0x2019:
					cString[i] = 0x92;
					break;
				case 0x201C:
					cString[i] = 0x93;
					break;
				case 0x201D:
					cString[i] = 0x94;
					break;
				case 0x2022:
					cString[i] = 0x95;
					break;
				case 0x2013:
					cString[i] = 0x96;
					break;
				case 0x2014:
					cString[i] = 0x97;
					break;
				case 0x2DC:
					cString[i] = 0x98;
					break;
				case 0x2122:
					cString[i] = 0x99;
					break;
				case 0x161:
					cString[i] = 0x9A;
					break;
				case 0x203A:
					cString[i] = 0x9B;
					break;
				case 0x153:
					cString[i] = 0x9C;
					break;
				case 0x17E:
					cString[i] = 0x9E;
					break;
				case 0x178:
					cString[i] = 0x9F;
					break;
				default:
					if (lossy)
						cString[i] = '?';
					else
						@throw
						    [OFInvalidEncodingException
						    exception];

					break;
				}
			} else
				cString[i] = (uint8_t)c;
		}

		cString[i] = '\0';

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







<
<
|
<
<
<
<
<
<
<
<
<
|
<
<
|
<

<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<






<
<
|
<
|
<
<
|
<
|
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







1060
1061
1062
1063
1064
1065
1066


1067









1068


1069

1070






1071





































1072
1073
1074
1075
1076
1077


1078

1079


1080

1081




1082






























































































1083
1084
1085
1086
1087
1088
1089
		cString[i] = '\0';

		return length;
	case OF_STRING_ENCODING_ISO_8859_15:
		if (length + 1 > maxLength)
			@throw [OFOutOfRangeException exception];



		if (!of_unicode_to_iso_8859_15(characters, cString, length,









		    lossy))


			@throw [OFInvalidEncodingException exception];








		cString[length] = '\0';






































		return length;
	case OF_STRING_ENCODING_WINDOWS_1252:
		if (length + 1 > maxLength)
			@throw [OFOutOfRangeException exception];



		if (!of_unicode_to_windows_1252(characters, cString, length,

		    lossy))


			@throw [OFInvalidEncodingException exception];






		cString[length] = '\0';































































































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

Modified src/iso_8859_15.m from [e4470d49c5] to [25eed555d5].

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



























































 * 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.
 */

#import "OFString.h"



const of_char16_t of_iso_8859_15[128] = {
	0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
	0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
	0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
	0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
	0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x20AC, 0x00A5, 0x0160, 0x00A7,
	0x0161, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
	0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x017D, 0x00B5, 0x00B6, 0x00B7,
	0x017E, 0x00B9, 0x00BA, 0x00BB, 0x0152, 0x0153, 0x0178, 0x00BF,
	0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
	0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
	0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
	0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
	0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
	0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
	0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
	0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF
};


































































>
>



















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
 * 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.
 */

#import "OFString.h"

#import "macros.h"

const of_char16_t of_iso_8859_15[128] = {
	0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
	0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
	0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
	0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
	0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x20AC, 0x00A5, 0x0160, 0x00A7,
	0x0161, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
	0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x017D, 0x00B5, 0x00B6, 0x00B7,
	0x017E, 0x00B9, 0x00BA, 0x00BB, 0x0152, 0x0153, 0x0178, 0x00BF,
	0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
	0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
	0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
	0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
	0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
	0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
	0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
	0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF
};

bool
of_unicode_to_iso_8859_15(const of_unichar_t *input, char *output,
    size_t length, bool lossy)
{
	size_t i;

	for (i = 0; i < length; i++) {
		of_unichar_t c = input[i];

		if OF_UNLIKELY (c == 0xA4 || c == 0xA6 || c == 0xA8 ||
		    c == 0xB4 || c == 0xB8 || c == 0xBC || c == 0xBD ||
		    c == 0xBE || c > 0xFFFF) {
			if (lossy)
				output[i] = '?';
			else
				return false;
		}

		if OF_UNLIKELY (c > 0xFF) {
			switch ((of_char16_t)c) {
			case 0x20AC:
				output[i] = 0xA4;
				break;
			case 0x160:
				output[i] = 0xA6;
				break;
			case 0x161:
				output[i] = 0xA8;
				break;
			case 0x17D:
				output[i] = 0xB4;
				break;
			case 0x17E:
				output[i] = 0xB8;
				break;
			case 0x152:
				output[i] = 0xBC;
				break;
			case 0x153:
				output[i] = 0xBD;
				break;
			case 0x178:
				output[i] = 0xBE;
				break;
			default:
				if (lossy)
					output[i] = '?';
				else
					return false;

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

	return true;
}

Modified src/windows_1252.m from [390d4ecb93] to [efb7bb469a].

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


















































































































 * 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.
 */

#import "OFString.h"



const of_char16_t of_windows_1252[128] = {
	0x20AC, 0xFFFD, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
	0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0xFFFD, 0x017D, 0xFFFD,
	0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
	0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0xFFFD, 0x017E, 0x0178,
	0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
	0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
	0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
	0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
	0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
	0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
	0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
	0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
	0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
	0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
	0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
	0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF
};

























































































































>
>



















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
 * 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.
 */

#import "OFString.h"

#import "macros.h"

const of_char16_t of_windows_1252[128] = {
	0x20AC, 0xFFFD, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
	0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0xFFFD, 0x017D, 0xFFFD,
	0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
	0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0xFFFD, 0x017E, 0x0178,
	0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
	0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
	0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
	0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
	0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
	0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
	0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
	0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
	0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
	0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
	0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
	0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF
};

bool
of_unicode_to_windows_1252(const of_unichar_t *input, char *output,
    size_t length, bool lossy)
{
	size_t i;

	for (i = 0; i < length; i++) {
		of_unichar_t c = input[i];

		if OF_UNLIKELY ((c >= 0x80 && c <= 0x9F) || c > 0xFFFF) {
			if (lossy)
				output[i] = '?';
			else
				return false;
		}

		if OF_UNLIKELY (c > 0xFF) {
			switch ((of_char16_t)c) {
			case 0x20AC:
				output[i] = 0x80;
				break;
			case 0x201A:
				output[i] = 0x82;
				break;
			case 0x192:
				output[i] = 0x83;
				break;
			case 0x201E:
				output[i] = 0x84;
				break;
			case 0x2026:
				output[i] = 0x85;
				break;
			case 0x2020:
				output[i] = 0x86;
				break;
			case 0x2021:
				output[i] = 0x87;
				break;
			case 0x2C6:
				output[i] = 0x88;
				break;
			case 0x2030:
				output[i] = 0x89;
				break;
			case 0x160:
				output[i] = 0x8A;
				break;
			case 0x2039:
				output[i] = 0x8B;
				break;
			case 0x152:
				output[i] = 0x8C;
				break;
			case 0x17D:
				output[i] = 0x8E;
				break;
			case 0x2018:
				output[i] = 0x91;
				break;
			case 0x2019:
				output[i] = 0x92;
				break;
			case 0x201C:
				output[i] = 0x93;
				break;
			case 0x201D:
				output[i] = 0x94;
				break;
			case 0x2022:
				output[i] = 0x95;
				break;
			case 0x2013:
				output[i] = 0x96;
				break;
			case 0x2014:
				output[i] = 0x97;
				break;
			case 0x2DC:
				output[i] = 0x98;
				break;
			case 0x2122:
				output[i] = 0x99;
				break;
			case 0x161:
				output[i] = 0x9A;
				break;
			case 0x203A:
				output[i] = 0x9B;
				break;
			case 0x153:
				output[i] = 0x9C;
				break;
			case 0x17E:
				output[i] = 0x9E;
				break;
			case 0x178:
				output[i] = 0x9F;
				break;
			default:
				if (lossy)
					output[i] = '?';
				else
					return false;

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

	return true;
}