2626@implementation WPStringUtils
2727
2828+ (NSString *)unescapedStringWithString : (NSString *)aString {
29+ if (!aString) {
30+ return nil ;
31+ }
32+
2933 NSMutableString *string = [NSMutableString stringWithString: aString];
30-
34+
3135 [string replaceOccurrencesOfString: @" "" withString: @" \" " options: NSLiteralSearch range: NSMakeRange (0 , [string length ])];
3236 [string replaceOccurrencesOfString: @" '" withString: @" '" options: NSLiteralSearch range: NSMakeRange (0 , [string length ])];
3337 [string replaceOccurrencesOfString: @" 9" withString: @" '" options: NSLiteralSearch range: NSMakeRange (0 , [string length ])];
@@ -36,19 +40,23 @@ + (NSString *)unescapedStringWithString:(NSString *)aString {
3640 [string replaceOccurrencesOfString: @" >" withString: @" >" options: NSLiteralSearch range: NSMakeRange (0 , [string length ])];
3741 [string replaceOccurrencesOfString: @" <" withString: @" <" options: NSLiteralSearch range: NSMakeRange (0 , [string length ])];
3842 [string replaceOccurrencesOfString: @" &" withString: @" &" options: NSLiteralSearch range: NSMakeRange (0 , [string length ])];
39-
43+
4044 return [NSString stringWithString: string];
4145}
4246
4347+ (NSString *)escapedStringWithString : (NSString *)aString {
48+ if (!aString) {
49+ return nil ;
50+ }
51+
4452 NSMutableString *string = [NSMutableString stringWithString: aString];
45-
53+
4654 // NOTE:we use unicode entities instead of & > < etc. since some hosts (powweb, fatcow, and similar)
4755 // have a weird PHP/libxml2 combination that ignores regular entities
4856 [string replaceOccurrencesOfString: @" &" withString: @" &" options: NSLiteralSearch range: NSMakeRange (0 , [string length ])];
4957 [string replaceOccurrencesOfString: @" >" withString: @" >" options: NSLiteralSearch range: NSMakeRange (0 , [string length ])];
5058 [string replaceOccurrencesOfString: @" <" withString: @" <" options: NSLiteralSearch range: NSMakeRange (0 , [string length ])];
51-
59+
5260 return [NSString stringWithString: string];
5361}
5462
0 commit comments