forked from bps/scrobblepod
-
Notifications
You must be signed in to change notification settings - Fork 3
/
NSString+SFHFUtils.m
36 lines (28 loc) · 1.45 KB
/
NSString+SFHFUtils.m
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
36
//
// NSString+SFHFUtils.m
// Delicious Client
//
// Created by Buzz Andersen on Fri May 14 2004.
// Copyright (c) 2004 Sci-Fi Hi-Fi. All rights reserved.
//
#import "NSString+SFHFUtils.h"
@implementation NSString (SFHFUtils)
- (NSString *) stringByUnescapingEntities: (NSDictionary *) entitiesDictionary {
NSString *unescapedString = (NSString *) CFXMLCreateStringByUnescapingEntities(NULL, (CFStringRef) self, (CFDictionaryRef) entitiesDictionary);
return [unescapedString autorelease];
}
- (NSString *) stringByAddingPercentEscapesUsingEncoding: (NSStringEncoding) encoding legalURLCharactersToBeEscaped: (NSString *) legalCharacters {
NSString *escapedString = (NSString *) CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef) self, NULL, (CFStringRef) legalCharacters, CFStringConvertNSStringEncodingToEncoding(encoding));
return [escapedString autorelease];
}
- (NSString *) stringByReplacingPercentEscapes {
return [(NSString*) CFURLCreateStringByReplacingPercentEscapes(NULL, (CFStringRef) self, CFSTR("")) autorelease];
}
- (NSString *)URLEncodedString {
NSString *legalURLCharactersToBeEscaped = @"&?";
CFStringRef percentEscapedString = CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)self, NULL, (CFStringRef)legalURLCharactersToBeEscaped, kCFStringEncodingUTF8);
NSString *retVal = [[NSString alloc] initWithString: (NSString *)percentEscapedString];
CFRelease(percentEscapedString);
return [retVal autorelease];
}
@end