Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I took Mike's work and turn it into a category for NSMutableString and NSString</p> <p><strong>Make a Category for NSMutableString with:</strong></p> <pre><code>- (NSMutableString *)xmlSimpleUnescape { [self replaceOccurrencesOfString:@"&amp;amp;" withString:@"&amp;" options:NSLiteralSearch range:NSMakeRange(0, [self length])]; [self replaceOccurrencesOfString:@"&amp;quot;" withString:@"\"" options:NSLiteralSearch range:NSMakeRange(0, [self length])]; [self replaceOccurrencesOfString:@"&amp;#x27;" withString:@"'" options:NSLiteralSearch range:NSMakeRange(0, [self length])]; [self replaceOccurrencesOfString:@"&amp;#39;" withString:@"'" options:NSLiteralSearch range:NSMakeRange(0, [self length])]; [self replaceOccurrencesOfString:@"&amp;#x92;" withString:@"'" options:NSLiteralSearch range:NSMakeRange(0, [self length])]; [self replaceOccurrencesOfString:@"&amp;#x96;" withString:@"-" options:NSLiteralSearch range:NSMakeRange(0, [self length])]; [self replaceOccurrencesOfString:@"&amp;gt;" withString:@"&gt;" options:NSLiteralSearch range:NSMakeRange(0, [self length])]; [self replaceOccurrencesOfString:@"&amp;lt;" withString:@"&lt;" options:NSLiteralSearch range:NSMakeRange(0, [self length])]; return self; } - (NSMutableString *)xmlSimpleEscape { [self replaceOccurrencesOfString:@"&amp;" withString:@"&amp;amp;" options:NSLiteralSearch range:NSMakeRange(0, [self length])]; [self replaceOccurrencesOfString:@"\"" withString:@"&amp;quot;" options:NSLiteralSearch range:NSMakeRange(0, [self length])]; [self replaceOccurrencesOfString:@"'" withString:@"&amp;#x27;" options:NSLiteralSearch range:NSMakeRange(0, [self length])]; [self replaceOccurrencesOfString:@"&gt;" withString:@"&amp;gt;" options:NSLiteralSearch range:NSMakeRange(0, [self length])]; [self replaceOccurrencesOfString:@"&lt;" withString:@"&amp;lt;" options:NSLiteralSearch range:NSMakeRange(0, [self length])]; return self; } </code></pre> <p><strong>Make a Category for NSString with:</strong></p> <pre><code>- (NSString *)xmlSimpleUnescapeString { NSMutableString *unescapeStr = [NSMutableString stringWithString:self]; return [unescapeStr xmlSimpleUnescape]; } - (NSString *)xmlSimpleEscapeString { NSMutableString *escapeStr = [NSMutableString stringWithString:self]; return [escapeStr xmlSimpleEscape]; } </code></pre> <p><strong>* A Swift 2.0 Version *</strong></p> <p>The Objective-C version is a little more efficient as it does mutable operations on the string. However, this is a swift way to do simple escaping:</p> <pre><code>extension String { typealias SimpleToFromRepalceList = [(fromSubString:String,toSubString:String)] // See http://stackoverflow.com/questions/24200888/any-way-to-replace-characters-on-swift-string // func simpleReplace( mapList:SimpleToFromRepalceList ) -&gt; String { var string = self for (fromStr, toStr) in mapList { let separatedList = string.componentsSeparatedByString(fromStr) if separatedList.count &gt; 1 { string = separatedList.joinWithSeparator(toStr) } } return string } func xmlSimpleUnescape() -&gt; String { let mapList : SimpleToFromRepalceList = [ ("&amp;amp;", "&amp;"), ("&amp;quot;", "\""), ("&amp;#x27;", "'"), ("&amp;#39;", "'"), ("&amp;#x92;", "'"), ("&amp;#x96;", "-"), ("&amp;gt;", "&gt;"), ("&amp;lt;", "&lt;")] return self.simpleReplace(mapList) } func xmlSimpleEscape() -&gt; String { let mapList : SimpleToFromRepalceList = [ ("&amp;", "&amp;amp;"), ("\"", "&amp;quot;"), ("'", "&amp;#x27;"), ("&gt;", "&amp;gt;"), ("&lt;", "&amp;lt;")] return self.simpleReplace(mapList) } } </code></pre> <p>I could have used the NSString bridging capabilities to write something very similar to the NSString version, but I decided to do it more swifty.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload