Created
September 26, 2012 10:34
-
-
Save leovandriel/3787259 to your computer and use it in GitHub Desktop.
Objective-C methods for percent-escaping NSString
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
// Objective-C methods for percent-escaping NSString, for use in NSURL. | |
// This approach does full escaping, instead of the 'smart' escaping that | |
// is provided by [NSString stringByReplacingPercentEscapesUsingEncoding:]. | |
// License: Public Domain | |
// Author: Leonard van Driel, 2012 | |
@implementation NSString (EscapeForURL) | |
- (NSString *)escapeForURL | |
{ | |
return (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef)self, NULL, CFSTR("*'();:@&=+$,/?!%#[]"), kCFStringEncodingUTF8)); | |
} | |
- (NSString *)unescapeForURL | |
{ | |
return (NSString *)CFBridgingRelease(CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL, (__bridge CFStringRef)self, CFSTR(""), kCFStringEncodingUTF8)); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment