ObjFW  Diff

Differences From Artifact [05ac91dbb0]:

To Artifact [f51e0ac16e]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20













-







/*
 * Copyright (c) 2008 - 2009
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of libobjfw. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#import "OFURLEncoding.h"
#import "OFExceptions.h"

42
43
44
45
46
47
48

49
50




51
52
53


54
55
56
57
58
59
60
41
42
43
44
45
46
47
48


49
50
51
52
53


54
55
56
57
58
59
60
61
62







+
-
-
+
+
+
+

-
-
+
+







						    andSize: (length * 3) + 1];

	for (i = 0; *s != '\0'; s++) {
		if (isalnum(*s) || *s == '-' || *s == '_' || *s == '.' ||
		    *s == '~')
			ret_c[i++] = *s;
		else {
			uint8_t high, low;
			char buf[3];
			snprintf(buf, 3, "%02X", *s);

			high = *s >> 4;
			low = *s & 0x0F;

			ret_c[i++] = '%';
			ret_c[i++] = buf[0];
			ret_c[i++] = buf[1];
			ret_c[i++] = (high > 9 ? high - 10 + 'A' : high + '0');
			ret_c[i++] = (low  > 9 ? low  - 10 + 'A' : low  + '0');
		}
	}
	ret_c[i] = '\0';

	@try {
		ret = [OFString stringWithCString: ret_c];
	} @finally {
87
88
89
90
91
92
93
94

95
96

97
98

99
100
101
102
103
104
105
89
90
91
92
93
94
95

96
97

98
99

100
101
102
103
104
105
106
107







-
+

-
+

-
+







				ret_c[i++] = ' ';
			else
				ret_c[i++] = *s;
			break;
		case 1:
		case 2:
			if (*s >= '0' && *s <= '9')
				c += (*s - '0') * (st == 1 ? 16 : 1);
				c += (*s - '0') << (st == 1 ? 4 : 0);
			else if (*s >= 'A' && *s <= 'F')
				c += (*s - 'A' + 10) * (st == 1 ? 16 : 1);
				c += (*s - 'A' + 10) << (st == 1 ? 4 : 0);
			else if (*s >= 'a' && *s <= 'f')
				c += (*s - 'a' + 10) * (st == 1 ? 16 : 1);
				c += (*s - 'a' + 10) << (st == 1 ? 4 : 0);
			else {
				free(ret_c);
				@throw [OFInvalidEncodingException
				    newWithClass: isa];
			}

			if (++st == 3) {