ObjFW  Diff

Differences From Artifact [9ad96294d0]:

To Artifact [92e75db2c6]:


26
27
28
29
30
31
32
33

34
35
36
37
38
39
40

/* Reference for static linking */
int _OFString_URLEncoding_reference;

@implementation OFString (URLEncoding)
- (OFString *)stringByURLEncoding
{
	return [self stringByURLEncodingWithAllowedCharacters: "$-_.!*()"];

}

- (OFString *)stringByURLEncodingWithAllowedCharacters: (const char *)allowed
{
	void *pool = objc_autoreleasePoolPush();
	const char *string = [self UTF8String];
	char *retCString;







|
>







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

/* Reference for static linking */
int _OFString_URLEncoding_reference;

@implementation OFString (URLEncoding)
- (OFString *)stringByURLEncoding
{
	return [self stringByURLEncodingWithAllowedCharacters:
	    "-._~!$&'()*+,;="];
}

- (OFString *)stringByURLEncodingWithAllowedCharacters: (const char *)allowed
{
	void *pool = objc_autoreleasePoolPush();
	const char *string = [self UTF8String];
	char *retCString;
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
	if ((retCString = malloc(([self UTF8StringLength] * 3) + 1)) == NULL)
		@throw [OFOutOfMemoryException exceptionWithRequestedSize:
		    ([self UTF8StringLength] * 3) + 1];

	for (i = 0; *string != '\0'; string++) {
		unsigned char c = *string;

		/*
		 * '+' is also listed in RFC 1738, however, '+' is sometimes
		 * interpreted as space in HTTP. Therefore always escape it to
		 * make sure it's always interpreted correctly.
		 */
		if (of_ascii_isalnum(c) || strchr(allowed, c) != NULL)
			retCString[i++] = c;
		else {
			unsigned char high, low;

			high = c >> 4;
			low = c & 0x0F;







<
<
<
<
<







50
51
52
53
54
55
56





57
58
59
60
61
62
63
	if ((retCString = malloc(([self UTF8StringLength] * 3) + 1)) == NULL)
		@throw [OFOutOfMemoryException exceptionWithRequestedSize:
		    ([self UTF8StringLength] * 3) + 1];

	for (i = 0; *string != '\0'; string++) {
		unsigned char c = *string;






		if (of_ascii_isalnum(c) || strchr(allowed, c) != NULL)
			retCString[i++] = c;
		else {
			unsigned char high, low;

			high = c >> 4;
			low = c & 0x0F;