-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSString+URLEncoding.m
executable file
·50 lines (38 loc) · 1.9 KB
/
NSString+URLEncoding.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
50
#import "NSString+URLEncoding.h"
@implementation NSString (OAURLEncodingAdditions)
- (NSString *)encodedURLString {
NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)self,
NULL, // characters to leave unescaped (NULL = all escaped sequences are replaced)
CFSTR("?=&+"), // legal URL characters to be escaped (NULL = all legal characters are replaced)
kCFStringEncodingUTF8); // encoding
return [result autorelease];
}
- (NSString *)encodedURLParameterString {
NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)self,
NULL,
CFSTR(":/=,!$&'()*+;[]@#?"),
kCFStringEncodingUTF8);
return [result autorelease];
}
- (NSString *)decodedURLString {
NSString *result = (NSString*)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault,
(CFStringRef)self,
CFSTR(""),
kCFStringEncodingUTF8);
return [result autorelease];
}
-(NSString *)removeQuotes
{
NSUInteger length = [self length];
NSString *ret = self;
if ([self characterAtIndex:0] == '"') {
ret = [ret substringFromIndex:1];
}
if ([self characterAtIndex:length - 1] == '"') {
ret = [ret substringToIndex:length - 2];
}
return ret;
}
@end