ObjFW  Check-in [44ea4f9322]

Overview
Comment:Reduce code duplication
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 44ea4f932205c339681f7835a564068cb2281589722400e25ef54617b127c9a9
User & Date: js on 2017-01-11 04:33:13
Other Links: manifest | tags
Context
2017-01-11
04:44
Accept cp* and cp-* as encoding name check-in: bbe91438b1 user: js tags: trunk
04:33
Reduce code duplication check-in: 44ea4f9322 user: js tags: trunk
04:22
Add Windows-1251 encoding check-in: 0f88ccfb04 user: js tags: trunk
Changes

Modified src/OFString.m from [c458b1a41f] to [3935514fea].

933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
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
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
	} else
# endif
# ifdef OF_HAVE_SOCKETS
	if ([scheme isEqual: @"http"] || [scheme isEqual: @"https"]) {
		OFHTTPClient *client = [OFHTTPClient client];
		OFHTTPRequest *request = [OFHTTPRequest requestWithURL: URL];
		OFHTTPResponse *response = [client performRequest: request];
		OFDictionary *headers;
		OFString *contentType, *contentLength;
		OFDataArray *data;

		if ([response statusCode] != 200)
			@throw [OFHTTPRequestFailedException
			    exceptionWithRequest: request
					response: response];

		headers = [response headers];

		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;
			else if ([contentType hasSuffix: @"charset=iso-8859-1"])
				encoding = OF_STRING_ENCODING_ISO_8859_1;
			else if ([contentType hasSuffix:
			    @"charset=iso-8859-15"])
				encoding = OF_STRING_ENCODING_ISO_8859_15;
			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;
			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];

		if ((contentLength = [headers
		    objectForKey: @"Content-Length"]) != nil)
			if ([data count] !=
			    (size_t)[contentLength decimalValue])
				@throw [OFTruncatedDataException exception];

		self = [[c alloc] initWithCString: (char*)[data items]
					 encoding: encoding
					   length: [data count]];
	} else
# endif
		@throw [OFUnsupportedProtocolException exception];

	objc_autoreleasePoolPop(pool);

	return self;







<
<
<






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







933
934
935
936
937
938
939



940
941
942
943
944
945

946




































947
948
949
950
951
952
953
	} else
# endif
# ifdef OF_HAVE_SOCKETS
	if ([scheme isEqual: @"http"] || [scheme isEqual: @"https"]) {
		OFHTTPClient *client = [OFHTTPClient client];
		OFHTTPRequest *request = [OFHTTPRequest requestWithURL: URL];
		OFHTTPResponse *response = [client performRequest: request];




		if ([response statusCode] != 200)
			@throw [OFHTTPRequestFailedException
			    exceptionWithRequest: request
					response: response];


		self = [[response string] retain];




































	} else
# endif
		@throw [OFUnsupportedProtocolException exception];

	objc_autoreleasePoolPop(pool);

	return self;