PageRenderTime 39ms CodeModel.GetById 1ms app.highlight 36ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/externals/google-toolbox-for-mac/Foundation/GTMNSString+URLArguments.m

http://macfuse.googlecode.com/
Objective C | 46 lines | 21 code | 6 blank | 19 comment | 0 complexity | c546fc7e40fccf4d9253880f86c25da5 MD5 | raw file
 1//
 2//  GTMNSString+URLArguments.m
 3//
 4//  Copyright 2006-2008 Google Inc.
 5//
 6//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
 7//  use this file except in compliance with the License.  You may obtain a copy
 8//  of the License at
 9// 
10//  http://www.apache.org/licenses/LICENSE-2.0
11// 
12//  Unless required by applicable law or agreed to in writing, software
13//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
15//  License for the specific language governing permissions and limitations under
16//  the License.
17//
18
19#import "GTMNSString+URLArguments.h"
20
21#import "GTMDefines.h"
22
23@implementation NSString (GTMNSStringURLArgumentsAdditions)
24
25- (NSString*)gtm_stringByEscapingForURLArgument {
26  // Encode all the reserved characters, per RFC 3986
27  // (<http://www.ietf.org/rfc/rfc3986.txt>)
28  CFStringRef escaped = 
29    CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
30                                            (CFStringRef)self,
31                                            NULL,
32                                            (CFStringRef)@"!*'();:@&=+$,/?%#[]",
33                                            kCFStringEncodingUTF8);
34  return GTMCFAutorelease(escaped);
35}
36
37- (NSString*)gtm_stringByUnescapingFromURLArgument {
38  NSMutableString *resultString = [NSMutableString stringWithString:self];
39  [resultString replaceOccurrencesOfString:@"+"
40                                withString:@" "
41                                   options:NSLiteralSearch
42                                     range:NSMakeRange(0, [resultString length])];
43  return [resultString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
44}
45
46@end