linphone-ios/Classes/Utils/XMLRPC/NSStringAdditions.m
2012-08-02 15:02:39 +02:00

46 lines
2.4 KiB
Objective-C
Executable file

#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: @"&lt;" 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 &amp; &gt; &lt; etc. since some hosts (powweb, fatcow, and similar)
// have a weird PHP/libxml2 combination that ignores regular entities
[string replaceOccurrencesOfString: @"&" withString: @"&#38;" options: NSLiteralSearch range: NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString: @">" withString: @"&#62;" options: NSLiteralSearch range: NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString: @"<" withString: @"&#60;" options: NSLiteralSearch range: NSMakeRange(0, [string length])];
return [NSString stringWithString: string];
}
@end