-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSStringAdditions.m
43 lines (31 loc) · 2.29 KB
/
NSStringAdditions.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
37
38
39
40
41
42
43
#import "NSStringAdditions.h"
@implementation NSString (NSStringAdditions)
+ (NSString *)stringByGeneratingUUID {
CFUUIDRef UUIDReference = CFUUIDCreate(nil);
CFStringRef temporaryUUIDString = CFUUIDCreateString(nil, UUIDReference);
CFRelease(UUIDReference);
return [NSMakeCollectable(temporaryUUIDString) autorelease];
}
#pragma mark -
- (NSString *)unescapedString {
NSMutableString *string = [NSMutableString stringWithString: self];
[string replaceOccurrencesOfString: @"&" withString: @"&" options: NSLiteralSearch range: NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString: @""" withString: @"\"" options: NSLiteralSearch range: NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString: @"'" withString: @"'" options: NSLiteralSearch range: NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString: @"9" withString: @"'" options: NSLiteralSearch range: NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString: @"’" withString: @"'" options: NSLiteralSearch range: NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString: @"–" withString: @"'" options: NSLiteralSearch range: NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString: @">" withString: @">" options: NSLiteralSearch range: NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString: @"<" withString: @"<" options: NSLiteralSearch range: NSMakeRange(0, [string length])];
return [NSString stringWithString: string];
}
- (NSString *)escapedString {
NSMutableString *string = [NSMutableString stringWithString: self];
// NOTE: we use unicode entities instead of & > < etc. since some hosts (powweb, fatcow, and similar)
// have a weird PHP/libxml2 combination that ignores regular entities
[string replaceOccurrencesOfString: @"&" withString: @"&" options: NSLiteralSearch range: NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString: @">" withString: @">" options: NSLiteralSearch range: NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString: @"<" withString: @"<" options: NSLiteralSearch range: NSMakeRange(0, [string length])];
return [NSString stringWithString: string];
}
@end