ObjFW  Diff

Differences From Artifact [6ffc687158]:

To Artifact [573e813f26]:

  • File src/OFURLEncoding.m — part of check-in [033054ad75] at 2009-05-29 19:21:57 on branch trunk — A few renames.

    OFExceptions:
    * OFNoMemException to OFOutOfMemoryException.
    * OFMemNotPartOfObjException to OFMemoryNotPartOfObjectException.

    OFObject:
    * -[addItemToMemoryPool:] to -[addMemoryToPool:].
    * -[allocWithSize:] to -[allocMemoryWithSize:].
    * -[allocNItems:withSize] to -[allocMemoryForNItems:withSize:].
    * -[resizeMem:toSize] to -[resizeMemory:toSize:].
    * -[resizeMem:toNItems:withSize:] to
    -[resizeMemoryToNItems:withSize:].
    * -[freeMem] to -[freeMemory:].

    OFString:
    * -[urlencode] to -[urlEncodedString].
    * -[urldecode] to -[urlDecodedString]. (user: js, size: 2336) [annotate] [blame] [check-ins using]


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#import "OFURLEncoding.h"
#import "OFExceptions.h"

/* Reference for static linking */
int _OFURLEncoding_reference;

@implementation OFString (OFURLEncoding)
- (OFString*)urlencode
{
	const char *s;
	char *ret_c;
	size_t i;
	OFString *ret;

	s = string;

	/*
	 * Worst case: 3 times longer than before.
	 * Oh, and we can't use [self allocWithSize:] here as self might be a
	 * @"" literal.
	 */
	if ((ret_c = malloc((length * 3) + 1)) == NULL)
		@throw [OFNoMemException newWithClass: isa
					      andSize: (length * 3) + 1];

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







|














|
|







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#import "OFURLEncoding.h"
#import "OFExceptions.h"

/* Reference for static linking */
int _OFURLEncoding_reference;

@implementation OFString (OFURLEncoding)
- (OFString*)urlEncodedString
{
	const char *s;
	char *ret_c;
	size_t i;
	OFString *ret;

	s = string;

	/*
	 * Worst case: 3 times longer than before.
	 * Oh, and we can't use [self allocWithSize:] here as self might be a
	 * @"" literal.
	 */
	if ((ret_c = malloc((length * 3) + 1)) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
						    andSize: (length * 3) + 1];

	for (i = 0; *s != '\0'; s++) {
		if (isalnum(*s) || *s == '-' || *s == '_' || *s == '.')
			ret_c[i++] = *s;
		else {
			char buf[3];
			snprintf(buf, 3, "%02X", *s);
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
	} @finally {
		free(ret_c);
	}

	return ret;
}

- (OFString*)urldecode
{
	const char *s;
	char *ret_c, c;
	size_t i;
	int st;
	OFString *ret;

	s = string;

	if ((ret_c = malloc(length + 1)) == NULL)
		@throw [OFNoMemException newWithClass: isa
					      andSize: length + 1];

	for (st = 0, i = 0, c = 0; *s; s++) {
		switch (st) {
		case 0:
			if (*s == '%')
				st = 1;
			else







|










|
|







59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
	} @finally {
		free(ret_c);
	}

	return ret;
}

- (OFString*)urlDecodedString
{
	const char *s;
	char *ret_c, c;
	size_t i;
	int st;
	OFString *ret;

	s = string;

	if ((ret_c = malloc(length + 1)) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
						    andSize: length + 1];

	for (st = 0, i = 0, c = 0; *s; s++) {
		switch (st) {
		case 0:
			if (*s == '%')
				st = 1;
			else