19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#include <stdlib.h>
#include <string.h>
#import "OFString+URLEncoding.h"
#import "OFCharacterSet.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfMemoryException.h"
/* Reference for static linking */
int _OFString_URLEncoding_reference;
@implementation OFString (URLEncoding)
- (OFString *)stringByURLEncodingWithAllowedCharacters:
|
>
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#include <stdlib.h>
#include <string.h>
#import "OFString+URLEncoding.h"
#import "OFCharacterSet.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidEncodingException.h"
#import "OFOutOfMemoryException.h"
/* Reference for static linking */
int _OFString_URLEncoding_reference;
@implementation OFString (URLEncoding)
- (OFString *)stringByURLEncodingWithAllowedCharacters:
|
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
of_unichar_t c = characters[i];
if (characterIsMember(allowedCharacters,
@selector(characterIsMember:), c))
[ret appendCharacters: &c
length: 1];
else {
unsigned char high = c >> 4;
unsigned char low = c & 0x0F;
of_unichar_t escaped[3];
escaped[0] = '%';
escaped[1] = (high > 9 ? high - 10 + 'A' : high + '0');
escaped[2] = (low > 9 ? low - 10 + 'A' : low + '0');
[ret appendCharacters: escaped
length: 3];
}
}
objc_autoreleasePoolPop(pool);
return ret;
}
|
>
>
>
>
>
>
>
>
|
|
|
|
>
|
>
|
|
|
>
|
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
of_unichar_t c = characters[i];
if (characterIsMember(allowedCharacters,
@selector(characterIsMember:), c))
[ret appendCharacters: &c
length: 1];
else {
char buffer[4];
size_t bufferLen;
if ((bufferLen = of_string_utf8_encode(c, buffer)) == 0)
@throw [OFInvalidEncodingException exception];
for (size_t j = 0; j < bufferLen; j++) {
unsigned char byte = buffer[j];
unsigned char high = byte >> 4;
unsigned char low = byte & 0x0F;
char escaped[3];
escaped[0] = '%';
escaped[1] =
(high > 9 ? high - 10 + 'A' : high + '0');
escaped[2] =
(low > 9 ? low - 10 + 'A' : low + '0');
[ret appendUTF8String: escaped
length: 3];
}
}
}
objc_autoreleasePoolPop(pool);
return ret;
}
|