#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