ObjFW  Check-in [0832fcf579]

Overview
Comment:Add Mac OS Roman encoding
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0832fcf579df3850f35da714f9524ab61d802eb74baa1f372272d6996f9c1b32
User & Date: js on 2017-01-10 23:23:40
Other Links: manifest | tags
Context
2017-01-10
23:45
Add missing files to Xcode project check-in: 8480d9e9c8 user: js tags: trunk
23:23
Add Mac OS Roman encoding check-in: 0832fcf579 user: js tags: trunk
21:38
Add codepage 850 check-in: 878c25c9d7 user: js tags: trunk
Changes

Modified src/Makefile from [a953a0f2ce] to [374f171e27].

154
155
156
157
158
159
160

161
162
163
164
165
166
167
	OFString_UTF8.m			\
	${AUTORELEASE_M}		\
	codepage_437.m			\
	codepage_850.m			\
	${FOUNDATION_COMPAT_M}		\
	${INSTANCE_M}			\
	iso_8859_15.m			\

	${UNICODE_M}			\
	windows_1252.m
SRCS_FILES += OFSettings_INIFile.m
SRCS_SOCKETS += ${OFKERNELEVENTOBSERVER_EPOLL_M}	\
		${OFKERNELEVENTOBSERVER_KQUEUE_M}	\
		${OFKERNELEVENTOBSERVER_POLL_M}		\
		${OFKERNELEVENTOBSERVER_SELECT_M}	\







>







154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
	OFString_UTF8.m			\
	${AUTORELEASE_M}		\
	codepage_437.m			\
	codepage_850.m			\
	${FOUNDATION_COMPAT_M}		\
	${INSTANCE_M}			\
	iso_8859_15.m			\
	mac_roman.m			\
	${UNICODE_M}			\
	windows_1252.m
SRCS_FILES += OFSettings_INIFile.m
SRCS_SOCKETS += ${OFKERNELEVENTOBSERVER_EPOLL_M}	\
		${OFKERNELEVENTOBSERVER_KQUEUE_M}	\
		${OFKERNELEVENTOBSERVER_POLL_M}		\
		${OFKERNELEVENTOBSERVER_SELECT_M}	\

Modified src/OFHTTPResponse.m from [0eddc32050] to [7bcf69b951].

115
116
117
118
119
120
121


122
123
124
125
126
127
128
			encoding = OF_STRING_ENCODING_UTF_8;
		if ([contentType hasSuffix: @"charset=iso-8859-1"])
			encoding = OF_STRING_ENCODING_ISO_8859_1;
		if ([contentType hasSuffix: @"charset=iso-8859-15"])
			encoding = OF_STRING_ENCODING_ISO_8859_15;
		if ([contentType hasSuffix: @"charset=windows-1252"])
			encoding = OF_STRING_ENCODING_WINDOWS_1252;


	}

	if (encoding == OF_STRING_ENCODING_AUTODETECT)
		encoding = OF_STRING_ENCODING_UTF_8;

	data = [self readDataArrayTillEndOfStream];








>
>







115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
			encoding = OF_STRING_ENCODING_UTF_8;
		if ([contentType hasSuffix: @"charset=iso-8859-1"])
			encoding = OF_STRING_ENCODING_ISO_8859_1;
		if ([contentType hasSuffix: @"charset=iso-8859-15"])
			encoding = OF_STRING_ENCODING_ISO_8859_15;
		if ([contentType hasSuffix: @"charset=windows-1252"])
			encoding = OF_STRING_ENCODING_WINDOWS_1252;
		if ([contentType hasSuffix: @"charset=macintosh"])
			encoding = OF_STRING_ENCODING_MAC_ROMAN;
	}

	if (encoding == OF_STRING_ENCODING_AUTODETECT)
		encoding = OF_STRING_ENCODING_UTF_8;

	data = [self readDataArrayTillEndOfStream];

Modified src/OFString.h from [ffba6d3d70] to [78eb3b06a4].

62
63
64
65
66
67
68


69
70
71
72
73
74
75
	OF_STRING_ENCODING_ISO_8859_15,
	/*! Windows-1252 */
	OF_STRING_ENCODING_WINDOWS_1252,
	/*! Codepage 437 */
	OF_STRING_ENCODING_CODEPAGE_437,
	/*! Codepage 850 */
	OF_STRING_ENCODING_CODEPAGE_850,


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







>
>







62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
	OF_STRING_ENCODING_ISO_8859_15,
	/*! Windows-1252 */
	OF_STRING_ENCODING_WINDOWS_1252,
	/*! Codepage 437 */
	OF_STRING_ENCODING_CODEPAGE_437,
	/*! Codepage 850 */
	OF_STRING_ENCODING_CODEPAGE_850,
	/*! Mac OS Roman */
	OF_STRING_ENCODING_MAC_ROMAN,
	/*! 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 [f0fd5cc4db] to [a66e682c7d].

85
86
87
88
89
90
91
92
93
94
95
96
97
98
99


100
101
102
103
104
105
106
		  lossy: (bool)lossy;
- (const char*)OF_cStringWithEncoding: (of_string_encoding_t)encoding
				lossy: (bool)lossy;
- (OFString*)OF_JSONRepresentationWithOptions: (int)options
					depth: (size_t)depth;
@end

extern bool of_unicode_to_iso_8859_15(const of_unichar_t*, uint8_t*, size_t,
    bool);
extern bool of_unicode_to_windows_1252(const of_unichar_t*, uint8_t*, size_t,
    bool);
extern bool of_unicode_to_codepage_437(const of_unichar_t*, uint8_t*, size_t,
    bool);
extern bool of_unicode_to_codepage_850(const of_unichar_t*, uint8_t*, size_t,
    bool);



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







|
|
|
|
|
|
|
|
>
>







85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
		  lossy: (bool)lossy;
- (const char*)OF_cStringWithEncoding: (of_string_encoding_t)encoding
				lossy: (bool)lossy;
- (OFString*)OF_JSONRepresentationWithOptions: (int)options
					depth: (size_t)depth;
@end

extern bool of_unicode_to_iso_8859_15(const of_unichar_t*, unsigned char*,
    size_t, bool);
extern bool of_unicode_to_windows_1252(const of_unichar_t*, unsigned char*,
    size_t, bool);
extern bool of_unicode_to_codepage_437(const of_unichar_t*, unsigned char*,
    size_t, bool);
extern bool of_unicode_to_codepage_850(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);

/* References for static linking */
void
_references_to_categories_of_OFString(void)
{
	_OFString_CryptoHashing_reference = 1;
	_OFString_JSONValue_reference = 1;
953
954
955
956
957
958
959


960
961
962
963
964
965
966
				encoding = OF_STRING_ENCODING_UTF_8;
			if ([contentType hasSuffix: @"charset=iso-8859-1"])
				encoding = OF_STRING_ENCODING_ISO_8859_1;
			if ([contentType hasSuffix: @"charset=iso-8859-15"])
				encoding = OF_STRING_ENCODING_ISO_8859_15;
			if ([contentType hasSuffix: @"charset=windows-1252"])
				encoding = OF_STRING_ENCODING_WINDOWS_1252;


		}

		if (encoding == OF_STRING_ENCODING_AUTODETECT)
			encoding = OF_STRING_ENCODING_UTF_8;

		data = [response readDataArrayTillEndOfStream];








>
>







955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
				encoding = OF_STRING_ENCODING_UTF_8;
			if ([contentType hasSuffix: @"charset=iso-8859-1"])
				encoding = OF_STRING_ENCODING_ISO_8859_1;
			if ([contentType hasSuffix: @"charset=iso-8859-15"])
				encoding = OF_STRING_ENCODING_ISO_8859_15;
			if ([contentType hasSuffix: @"charset=windows-1252"])
				encoding = OF_STRING_ENCODING_WINDOWS_1252;
			if ([contentType hasSuffix: @"charset=macintosh"])
				encoding = OF_STRING_ENCODING_MAC_ROMAN;
		}

		if (encoding == OF_STRING_ENCODING_AUTODETECT)
			encoding = OF_STRING_ENCODING_UTF_8;

		data = [response readDataArrayTillEndOfStream];

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
			if OF_UNLIKELY (characters[i] > 0x80) {
				if (lossy)
					cString[i] = '?';
				else
					@throw [OFInvalidEncodingException
					    exception];
			} else
				cString[i] = (char)characters[i];
		}

		cString[i] = '\0';

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

		for (i = 0; i < length; i++) {
			if OF_UNLIKELY (characters[i] > 0xFF) {
				if (lossy)
					cString[i] = '?';
				else
					@throw [OFInvalidEncodingException
					    exception];
			} else
				cString[i] = (uint8_t)characters[i];
		}

		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, (uint8_t*)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, (uint8_t*)cString,
		    length, lossy))
			@throw [OFInvalidEncodingException exception];

		cString[length] = '\0';

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

		if (!of_unicode_to_codepage_437(characters, (uint8_t*)cString,
		    length, lossy))
			@throw [OFInvalidEncodingException exception];

		cString[length] = '\0';

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

		if (!of_unicode_to_codepage_850(characters, (uint8_t*)cString,
		    length, lossy))











			@throw [OFInvalidEncodingException exception];

		cString[length] = '\0';

		return length;
	default:
		@throw [OFNotImplementedException exceptionWithSelector: _cmd







|

















|









|
|









|
|









|
|









|
|
>
>
>
>
>
>
>
>
>
>
>







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
			if OF_UNLIKELY (characters[i] > 0x80) {
				if (lossy)
					cString[i] = '?';
				else
					@throw [OFInvalidEncodingException
					    exception];
			} else
				cString[i] = (unsigned char)characters[i];
		}

		cString[i] = '\0';

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

		for (i = 0; i < length; i++) {
			if OF_UNLIKELY (characters[i] > 0xFF) {
				if (lossy)
					cString[i] = '?';
				else
					@throw [OFInvalidEncodingException
					    exception];
			} else
				cString[i] = (unsigned char)characters[i];
		}

		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,
		    (unsigned char*)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,
		    (unsigned char*)cString, length, lossy))
			@throw [OFInvalidEncodingException exception];

		cString[length] = '\0';

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

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

		cString[length] = '\0';

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

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

		cString[length] = '\0';

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

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

		cString[length] = '\0';

		return length;
	default:
		@throw [OFNotImplementedException exceptionWithSelector: _cmd
1190
1191
1192
1193
1194
1195
1196

1197
1198
1199
1200
1201
1202
1203
		break;
	case OF_STRING_ENCODING_ASCII:
	case OF_STRING_ENCODING_ISO_8859_1:
	case OF_STRING_ENCODING_ISO_8859_15:
	case OF_STRING_ENCODING_WINDOWS_1252:
	case OF_STRING_ENCODING_CODEPAGE_437:
	case OF_STRING_ENCODING_CODEPAGE_850:

		cString = [object allocMemoryWithSize: length + 1];

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








>







1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
		break;
	case OF_STRING_ENCODING_ASCII:
	case OF_STRING_ENCODING_ISO_8859_1:
	case OF_STRING_ENCODING_ISO_8859_15:
	case OF_STRING_ENCODING_WINDOWS_1252:
	case OF_STRING_ENCODING_CODEPAGE_437:
	case OF_STRING_ENCODING_CODEPAGE_850:
	case OF_STRING_ENCODING_MAC_ROMAN:
		cString = [object allocMemoryWithSize: length + 1];

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

1255
1256
1257
1258
1259
1260
1261

1262
1263
1264
1265
1266
1267
1268
		return UTF8StringLength;
	case OF_STRING_ENCODING_ASCII:
	case OF_STRING_ENCODING_ISO_8859_1:
	case OF_STRING_ENCODING_ISO_8859_15:
	case OF_STRING_ENCODING_WINDOWS_1252:
	case OF_STRING_ENCODING_CODEPAGE_437:
	case OF_STRING_ENCODING_CODEPAGE_850:

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

- (size_t)UTF8StringLength







>







1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
		return UTF8StringLength;
	case OF_STRING_ENCODING_ASCII:
	case OF_STRING_ENCODING_ISO_8859_1:
	case OF_STRING_ENCODING_ISO_8859_15:
	case OF_STRING_ENCODING_WINDOWS_1252:
	case OF_STRING_ENCODING_CODEPAGE_437:
	case OF_STRING_ENCODING_CODEPAGE_850:
	case OF_STRING_ENCODING_MAC_ROMAN:
		return [self length];
	default:
		@throw [OFInvalidEncodingException exception];
	}
}

- (size_t)UTF8StringLength

Modified src/OFString_UTF8.m from [fdc7ecf620] to [293372453e].

38
39
40
41
42
43
44

45
46
47
48
49
50
51
#import "of_asprintf.h"
#import "unicode.h"

extern const of_char16_t of_iso_8859_15[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];


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];







>







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#import "of_asprintf.h"
#import "unicode.h"

extern const of_char16_t of_iso_8859_15[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_mac_roman[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];
294
295
296
297
298
299
300



301
302
303
304
305
306
307
			table = of_windows_1252;
			break;
		case OF_STRING_ENCODING_CODEPAGE_437:
			table = of_codepage_437;
			break;
		case OF_STRING_ENCODING_CODEPAGE_850:
			table = of_codepage_850;



			break;
		default:
			@throw [OFInvalidEncodingException exception];
		}

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







>
>
>







295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
			table = of_windows_1252;
			break;
		case OF_STRING_ENCODING_CODEPAGE_437:
			table = of_codepage_437;
			break;
		case OF_STRING_ENCODING_CODEPAGE_850:
			table = of_codepage_850;
			break;
		case OF_STRING_ENCODING_MAC_ROMAN:
			table = of_mac_roman;
			break;
		default:
			@throw [OFInvalidEncodingException exception];
		}

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

Modified src/OFXMLParser.m from [8d14cdf4ec] to [ab4dd1b1f9].

471
472
473
474
475
476
477



478
479
480
481
482
483
484
					    OF_STRING_ENCODING_ISO_8859_1;
				else if ([value isEqual: @"iso-8859-15"])
					_encoding =
					    OF_STRING_ENCODING_ISO_8859_15;
				else if ([value isEqual: @"windows-1252"])
					_encoding =
					    OF_STRING_ENCODING_WINDOWS_1252;



				else
					return false;
			}

			last = i + 1;
			PIState = 0;








>
>
>







471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
					    OF_STRING_ENCODING_ISO_8859_1;
				else if ([value isEqual: @"iso-8859-15"])
					_encoding =
					    OF_STRING_ENCODING_ISO_8859_15;
				else if ([value isEqual: @"windows-1252"])
					_encoding =
					    OF_STRING_ENCODING_WINDOWS_1252;
				else if ([value isEqual: @"macintosh"])
					_encoding =
					    OF_STRING_ENCODING_MAC_ROMAN;
				else
					return false;
			}

			last = i + 1;
			PIState = 0;

Modified src/codepage_437.m from [4fbb269eea] to [4f116b23ee].

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4,
	0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
	0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248,
	0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
};

bool
of_unicode_to_codepage_437(const of_unichar_t *input, uint8_t *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) {







|







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4,
	0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
	0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248,
	0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
};

bool
of_unicode_to_codepage_437(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) {

Modified src/codepage_850.m from [f036557b58] to [f974a5af73].

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE,
	0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4,
	0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8,
	0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
};

bool
of_unicode_to_codepage_850(const of_unichar_t *input, uint8_t *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) {







|







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE,
	0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4,
	0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8,
	0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
};

bool
of_unicode_to_codepage_850(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) {

Modified src/iso_8859_15.m from [e704902e2d] to [42aeba380c].

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	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, uint8_t *output,
    size_t length, bool lossy)
{
	for (size_t i = 0; i < length; i++) {
		of_unichar_t c = input[i];

		if OF_UNLIKELY (c > 0xFF) {
			if OF_UNLIKELY (c > 0xFFFF) {







|







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	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, 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 > 0xFF) {
			if OF_UNLIKELY (c > 0xFFFF) {

Added src/mac_roman.m version [43f23cd031].













































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
/*
 * 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_mac_roman[128] = {
	0x00C4, 0x00C5, 0x00C7, 0x00C9, 0x00D1, 0x00D6, 0x00DC, 0x00E1,
	0x00E0, 0x00E2, 0x00E4, 0x00E3, 0x00E5, 0x00E7, 0x00E9, 0x00E8,
	0x00EA, 0x00EB, 0x00ED, 0x00EC, 0x00EE, 0x00EF, 0x00F1, 0x00F3,
	0x00F2, 0x00F4, 0x00F6, 0x00F5, 0x00FA, 0x00F9, 0x00FB, 0x00FC,
	0x2020, 0x00B0, 0x00A2, 0x00A3, 0x00A7, 0x2022, 0x00B6, 0x00DF,
	0x00AE, 0x00A9, 0x2122, 0x00B4, 0x00A8, 0x2260, 0x00C6, 0x00D8,
	0x221E, 0x00B1, 0x2264, 0x2265, 0x00A5, 0x00B5, 0x2202, 0x2211,
	0x220F, 0x03c0, 0x222B, 0x00AA, 0x00BA, 0x03A9, 0x00E6, 0x00F8,
	0x00BF, 0x00A1, 0x00AC, 0x221A, 0x0192, 0x2248, 0x2206, 0x00AB,
	0x00BB, 0x2026, 0x00A0, 0x00C0, 0x00C3, 0x00D5, 0x0152, 0x0153,
	0x2013, 0x2014, 0x201C, 0x201D, 0x2018, 0x2019, 0x00F7, 0x25CA,
	0x00FF, 0x0178, 0x2044, 0x20AC, 0x2039, 0x203A, 0xFB01, 0xFB02,
	0x2021, 0x00B7, 0x201A, 0x201E, 0x2030, 0x00C2, 0x00CA, 0x00C1,
	0x00CB, 0x00C8, 0x00CD, 0x00CE, 0x00CF, 0x00CC, 0x00D3, 0x00D4,
	0xF8FF, 0x00D2, 0x00DA, 0x00DB, 0x00D9, 0x0131, 0x02C6, 0x02DC,
	0x00AF, 0x02D8, 0x02D9, 0x02DA, 0x00B8, 0x02DD, 0x02DB, 0x02C7
};

bool
of_unicode_to_mac_roman(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;
			}

			switch ((of_char16_t)c) {
			case 0xC4:
				output[i] = 0x80;
				break;
			case 0xC5:
				output[i] = 0x81;
				break;
			case 0xC7:
				output[i] = 0x82;
				break;
			case 0xC9:
				output[i] = 0x83;
				break;
			case 0xD1:
				output[i] = 0x84;
				break;
			case 0xD6:
				output[i] = 0x85;
				break;
			case 0xDC:
				output[i] = 0x86;
				break;
			case 0xE1:
				output[i] = 0x87;
				break;
			case 0xE0:
				output[i] = 0x88;
				break;
			case 0xE2:
				output[i] = 0x89;
				break;
			case 0xE4:
				output[i] = 0x8A;
				break;
			case 0xE3:
				output[i] = 0x8B;
				break;
			case 0xE5:
				output[i] = 0x8C;
				break;
			case 0xE7:
				output[i] = 0x8D;
				break;
			case 0xE9:
				output[i] = 0x8E;
				break;
			case 0xE8:
				output[i] = 0x8F;
				break;
			case 0xEA:
				output[i] = 0x90;
				break;
			case 0xEB:
				output[i] = 0x91;
				break;
			case 0xED:
				output[i] = 0x92;
				break;
			case 0xEC:
				output[i] = 0x93;
				break;
			case 0xEE:
				output[i] = 0x94;
				break;
			case 0xEF:
				output[i] = 0x95;
				break;
			case 0xF1:
				output[i] = 0x96;
				break;
			case 0xF3:
				output[i] = 0x97;
				break;
			case 0xF2:
				output[i] = 0x98;
				break;
			case 0xF4:
				output[i] = 0x99;
				break;
			case 0xF6:
				output[i] = 0x9A;
				break;
			case 0xF5:
				output[i] = 0x9B;
				break;
			case 0xFA:
				output[i] = 0x9C;
				break;
			case 0xF9:
				output[i] = 0x9D;
				break;
			case 0xFB:
				output[i] = 0x9E;
				break;
			case 0xFC:
				output[i] = 0x9F;
				break;
			case 0x2020:
				output[i] = 0xA0;
				break;
			case 0xB0:
				output[i] = 0xA1;
				break;
			case 0xA2:
				output[i] = 0xA2;
				break;
			case 0xA3:
				output[i] = 0xA3;
				break;
			case 0xA7:
				output[i] = 0xA4;
				break;
			case 0x2022:
				output[i] = 0xA5;
				break;
			case 0xB6:
				output[i] = 0xA6;
				break;
			case 0xDF:
				output[i] = 0xA7;
				break;
			case 0xAE:
				output[i] = 0xA8;
				break;
			case 0xA9:
				output[i] = 0xA9;
				break;
			case 0x2122:
				output[i] = 0xAA;
				break;
			case 0xB4:
				output[i] = 0xAB;
				break;
			case 0xA8:
				output[i] = 0xAC;
				break;
			case 0x2260:
				output[i] = 0xAD;
				break;
			case 0xC6:
				output[i] = 0xAE;
				break;
			case 0xD8:
				output[i] = 0xAF;
				break;
			case 0x221E:
				output[i] = 0xB0;
				break;
			case 0xB1:
				output[i] = 0xB1;
				break;
			case 0x2264:
				output[i] = 0xB2;
				break;
			case 0x2265:
				output[i] = 0xB3;
				break;
			case 0xA5:
				output[i] = 0xB4;
				break;
			case 0xB5:
				output[i] = 0xB5;
				break;
			case 0x2202:
				output[i] = 0xB6;
				break;
			case 0x2211:
				output[i] = 0xB7;
				break;
			case 0x220F:
				output[i] = 0xB8;
				break;
			case 0x3C0:
				output[i] = 0xB9;
				break;
			case 0x222B:
				output[i] = 0xBA;
				break;
			case 0xAA:
				output[i] = 0xBB;
				break;
			case 0xBA:
				output[i] = 0xBC;
				break;
			case 0x3A9:
				output[i] = 0xBD;
				break;
			case 0xE6:
				output[i] = 0xBE;
				break;
			case 0xF8:
				output[i] = 0xBF;
				break;
			case 0xBF:
				output[i] = 0xC0;
				break;
			case 0xA1:
				output[i] = 0xC1;
				break;
			case 0xAC:
				output[i] = 0xC2;
				break;
			case 0x221A:
				output[i] = 0xC3;
				break;
			case 0x192:
				output[i] = 0xC4;
				break;
			case 0x2248:
				output[i] = 0xC5;
				break;
			case 0x2206:
				output[i] = 0xC6;
				break;
			case 0xAB:
				output[i] = 0xC7;
				break;
			case 0xBB:
				output[i] = 0xC8;
				break;
			case 0x2026:
				output[i] = 0xC9;
				break;
			case 0xA0:
				output[i] = 0xCA;
				break;
			case 0xC0:
				output[i] = 0xCB;
				break;
			case 0xC3:
				output[i] = 0xCC;
				break;
			case 0xD5:
				output[i] = 0xCD;
				break;
			case 0x152:
				output[i] = 0xCE;
				break;
			case 0x153:
				output[i] = 0xCF;
				break;
			case 0x2013:
				output[i] = 0xD0;
				break;
			case 0x2014:
				output[i] = 0xD1;
				break;
			case 0x201C:
				output[i] = 0xD2;
				break;
			case 0x201D:
				output[i] = 0xD3;
				break;
			case 0x2018:
				output[i] = 0xD4;
				break;
			case 0x2019:
				output[i] = 0xD5;
				break;
			case 0xF7:
				output[i] = 0xD6;
				break;
			case 0x25CA:
				output[i] = 0xD7;
				break;
			case 0xFF:
				output[i] = 0xD8;
				break;
			case 0x178:
				output[i] = 0xD9;
				break;
			case 0x2044:
				output[i] = 0xDA;
				break;
			case 0x20AC:
				output[i] = 0xDB;
				break;
			case 0x2039:
				output[i] = 0xDC;
				break;
			case 0x203A:
				output[i] = 0xDD;
				break;
			case 0xFB01:
				output[i] = 0xDE;
				break;
			case 0xFB02:
				output[i] = 0xDF;
				break;
			case 0x2021:
				output[i] = 0xE0;
				break;
			case 0xB7:
				output[i] = 0xE1;
				break;
			case 0x201A:
				output[i] = 0xE2;
				break;
			case 0x201E:
				output[i] = 0xE3;
				break;
			case 0x2030:
				output[i] = 0xE4;
				break;
			case 0xC2:
				output[i] = 0xE5;
				break;
			case 0xCA:
				output[i] = 0xE6;
				break;
			case 0xC1:
				output[i] = 0xE7;
				break;
			case 0xCB:
				output[i] = 0xE8;
				break;
			case 0xC8:
				output[i] = 0xE9;
				break;
			case 0xCD:
				output[i] = 0xEA;
				break;
			case 0xCE:
				output[i] = 0xEB;
				break;
			case 0xCF:
				output[i] = 0xEC;
				break;
			case 0xCC:
				output[i] = 0xED;
				break;
			case 0xD3:
				output[i] = 0xEE;
				break;
			case 0xD4:
				output[i] = 0xEF;
				break;
			case 0xF8FF:
				output[i] = 0xF0;
				break;
			case 0xD2:
				output[i] = 0xF1;
				break;
			case 0xDA:
				output[i] = 0xF2;
				break;
			case 0xDB:
				output[i] = 0xF3;
				break;
			case 0xD9:
				output[i] = 0xF4;
				break;
			case 0x131:
				output[i] = 0xF5;
				break;
			case 0x2C6:
				output[i] = 0xF6;
				break;
			case 0x2DC:
				output[i] = 0xF7;
				break;
			case 0xAF:
				output[i] = 0xF8;
				break;
			case 0x2D8:
				output[i] = 0xF9;
				break;
			case 0x2D9:
				output[i] = 0xFA;
				break;
			case 0x2DA:
				output[i] = 0xFB;
				break;
			case 0xB8:
				output[i] = 0xFC;
				break;
			case 0x2DD:
				output[i] = 0xFD;
				break;
			case 0x2DB:
				output[i] = 0xFE;
				break;
			case 0x2C7:
				output[i] = 0xFF;
				break;
			default:
				if (lossy)
					output[i] = '?';
				else
					return false;

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

	return true;
}

Modified src/windows_1252.m from [223e23ea0d] to [dc1b68f1d7].

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	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, uint8_t *output,
    size_t length, bool lossy)
{
	for (size_t i = 0; i < length; i++) {
		of_unichar_t c = input[i];

		if OF_UNLIKELY (c > 0xFF) {
			if OF_UNLIKELY (c > 0xFFFF) {







|







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	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, 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 > 0xFF) {
			if OF_UNLIKELY (c > 0xFFFF) {