ObjFW  Diff

Differences From Artifact [a66e682c7d]:

To Artifact [c458b1a41f]:


87
88
89
90
91
92
93


94
95
96
97
98
99
100
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102







+
+







				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_1251(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*,
949
950
951
952
953
954
955
956

957
958


959
960





961
962

963
964
965
966
967
968
969
951
952
953
954
955
956
957

958
959

960
961
962

963
964
965
966
967
968

969
970
971
972
973
974
975
976







-
+

-
+
+

-
+
+
+
+
+

-
+







		if (encoding == OF_STRING_ENCODING_AUTODETECT &&
		    (contentType = [headers
		    objectForKey: @"Content-Type"]) != nil) {
			contentType = [contentType lowercaseString];

			if ([contentType hasSuffix: @"charset=utf-8"])
				encoding = OF_STRING_ENCODING_UTF_8;
			if ([contentType hasSuffix: @"charset=iso-8859-1"])
			else if ([contentType hasSuffix: @"charset=iso-8859-1"])
				encoding = OF_STRING_ENCODING_ISO_8859_1;
			if ([contentType hasSuffix: @"charset=iso-8859-15"])
			else if ([contentType hasSuffix:
			    @"charset=iso-8859-15"])
				encoding = OF_STRING_ENCODING_ISO_8859_15;
			if ([contentType hasSuffix: @"charset=windows-1252"])
			else if ([contentType hasSuffix:
			    @"charset=windows-1251"])
				encoding = OF_STRING_ENCODING_WINDOWS_1251;
			else if ([contentType hasSuffix:
			    @"charset=windows-1252"])
				encoding = OF_STRING_ENCODING_WINDOWS_1252;
			if ([contentType hasSuffix: @"charset=macintosh"])
			else 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];
1102
1103
1104
1105
1106
1107
1108











1109
1110
1111
1112
1113
1114
1115
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







+
+
+
+
+
+
+
+
+
+
+








		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_1251:
		if (length + 1 > maxLength)
			@throw [OFOutOfRangeException exception];

		if (!of_unicode_to_windows_1251(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))
1202
1203
1204
1205
1206
1207
1208

1209
1210
1211
1212
1213
1214
1215
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234







+







			/* We don't care, as we only tried to make it smaller */
		}

		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_1251:
	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
1268
1269
1270
1271
1272
1273
1274

1275
1276
1277
1278
1279
1280
1281
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301







+







			UTF8StringLength += len;
		}

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