This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
forked from eczarny/xmlrpc
-
Notifications
You must be signed in to change notification settings - Fork 29
/
NSStringAdditions.m
46 lines (35 loc) · 2.39 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
44
45
46
#import "NSStringAdditions.h"
@implementation NSString (NSStringAdditions)
+ (NSString *)stringByGeneratingUUID {
CFUUIDRef UUIDReference = CFUUIDCreate(nil);
CFStringRef temporaryUUIDString = CFUUIDCreateString(nil, UUIDReference);
CFRelease(UUIDReference);
#if ! __has_feature(objc_arc)
return [NSMakeCollectable(temporaryUUIDString) autorelease];
#else
return (__bridge_transfer NSString*)temporaryUUIDString;
#endif
}
#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