ObjFW  Diff

Differences From Artifact [4455805b29]:

To Artifact [0c0207b5a6]:


80
81
82
83
84
85
86
87

88
89
90
91
92

93
94
95
96
97
98
99
100
101
80
81
82
83
84
85
86

87
88
89
90
91

92


93
94
95
96
97
98
99







-
+




-
+
-
-







}

- (OFString *)stringByURLDecoding
{
	void *pool = objc_autoreleasePoolPush();
	const char *string = self.UTF8String;
	size_t length = self.UTF8StringLength;
	char *retCString, *retCString2;
	char *retCString;
	char byte = 0;
	int state = 0;
	size_t i = 0;

	if ((retCString = malloc(length + 1)) == NULL)
	retCString = of_malloc(1, length + 1);
		@throw [OFOutOfMemoryException
		    exceptionWithRequestedSize: length + 1];

	while (length--) {
		char c = *string++;

		switch (state) {
		case 0:
			if (c == '%')
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
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







-
+

















-
+



+
+
+
-
+
-
-
-
-
+
+
+




			if (c >= '0' && c <= '9')
				byte += (c - '0') << shift;
			else if (c >= 'A' && c <= 'F')
				byte += (c - 'A' + 10) << shift;
			else if (c >= 'a' && c <= 'f')
				byte += (c - 'a' + 10) << shift;
			else {
				free(retCString);
				of_free(retCString);
				@throw [OFInvalidFormatException exception];
			}

			if (++state == 3) {
				retCString[i++] = byte;
				state = 0;
				byte = 0;
			}

			break;
		}
	}
	retCString[i] = '\0';

	objc_autoreleasePoolPop(pool);

	if (state != 0) {
		free(retCString);
		of_free(retCString);
		@throw [OFInvalidFormatException exception];
	}

	@try {
		retCString = of_realloc(retCString, 1, i + 1);
	} @catch (OFOutOfMemoryException *e) {
	/* We don't care if it fails, as we only made it smaller. */
		/* We don't care if it fails, as we only made it smaller. */
	if ((retCString2 = realloc(retCString, i + 1)) == NULL)
		retCString2 = retCString;

	return [OFString stringWithUTF8StringNoCopy: retCString2
	}

	return [OFString stringWithUTF8StringNoCopy: retCString
					     length: i
				       freeWhenDone: true];
}
@end