Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

40 lines (30 sloc) 1.152 kb
//
// NSString+QueryString.m
// LROAuth2Client
//
// Created by Luke Redpath on 14/05/2010.
// Copyright 2010 LJR Software Limited. All rights reserved.
//
#import "NSString+QueryString.h"
@implementation NSString (QueryString)
- (NSString*)stringByEscapingForURLQuery
{
NSString *result = self;
CFStringRef originalAsCFString = (__bridge CFStringRef) self;
CFStringRef leaveAlone = CFSTR(" ");
CFStringRef toEscape = CFSTR("\n\r?[]()$,!'*;:@&=#%+/");
CFStringRef escapedStr;
escapedStr = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, originalAsCFString, leaveAlone, toEscape, kCFStringEncodingUTF8);
if (escapedStr) {
NSMutableString *mutable = [NSMutableString stringWithString:(__bridge NSString *)escapedStr];
CFRelease(escapedStr);
[mutable replaceOccurrencesOfString:@" " withString:@"+" options:0 range:NSMakeRange(0, [mutable length])];
result = mutable;
}
return result;
}
- (NSString*)stringByUnescapingFromURLQuery
{
return [[self stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] stringByReplacingOccurrencesOfString:@"+" withString:@" "];
}
@end
Jump to Line
Something went wrong with that request. Please try again.