Created
March 28, 2011 17:51
-
-
Save fxbeckers/890923 to your computer and use it in GitHub Desktop.
Straightforward way of performing URL encoding and decoding of strings, especially useful for use in conjunction with TTNavigtor and URL Mapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface NSString (FXNSStringAdditions) | |
- (NSString *)urlEncoded; | |
- (NSString *)urlDecoded; | |
@end | |
@implementation NSString (FXNSStringAdditions) | |
- (NSString *)urlEncoded { | |
NSString *result = (NSString *) | |
CFURLCreateStringByAddingPercentEscapes (kCFAllocatorDefault,(CFStringRef)self, NULL, CFSTR(":/?# []@!$&’()*+,;="), kCFStringEncodingASCII); | |
return [result autorelease]; | |
} | |
- (NSString *)urlDecoded { | |
NSString *result = (NSString *) | |
CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (CFStringRef)self,CFSTR(""), kCFStringEncodingASCII); | |
return [result autorelease]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment