-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNSString+EncodingURL.m
More file actions
36 lines (27 loc) · 909 Bytes
/
NSString+EncodingURL.m
File metadata and controls
36 lines (27 loc) · 909 Bytes
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
#import "NSString+EncodingURL.h"
@implementation NSString (EncodingURL)
//----------------------------------------------------------------------------//
#pragma mark -- APIs --
//----------------------------------------------------------------------------//
- (NSString *)stringByEncodingURL
{
NSMutableString *result = [NSMutableString string];
for (const char *source = [self UTF8String]; *source; source++) {
unsigned char append = *source;
NSString* format = @"%c";
if (' ' == append) {
append = '+';
} else if (!(
'0' <= append && append <= '9'
|| 'A' <= append && append <= 'Z'
|| 'a' <= append && append <= 'z'
|| '-' == append
|| '_' == append
)) {
format = @"%%%02X";
}
[result appendFormat:format, append];
}
return result;
}
@end