@Override protected void toASCII(StringBuilder ascii, int level) { this.indent(ascii, level); ascii.append("\""); //According to https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/PropertyLists/OldStylePlists/OldStylePLists.html //non-ASCII characters are not escaped but simply written into the //file, thus actually violating the ASCII plain text format. //We will escape the string anyway because current Xcode project files (ASCII property lists) also escape their strings. ascii.append(escapeStringForASCII(this.content)); ascii.append("\""); }
@Override protected void toASCIIGnuStep(StringBuilder ascii, int level) { this.indent(ascii, level); ascii.append("\""); ascii.append(escapeStringForASCII(this.content)); ascii.append("\""); }
@Override void toXML(StringBuilder xml, int level) { this.indent(xml, level); xml.append("<string>"); //Make sure that the string is encoded in UTF-8 for the XML output synchronized (NSString.class) { if (utf8Encoder == null) utf8Encoder = Charset.forName("UTF-8").newEncoder(); else utf8Encoder.reset(); try { ByteBuffer byteBuf = utf8Encoder.encode(CharBuffer.wrap(this.content)); byte[] bytes = new byte[byteBuf.remaining()]; byteBuf.get(bytes); this.content = new String(bytes, "UTF-8"); } catch (Exception ex) { throw new RuntimeException("Could not encode the NSString into UTF-8: " + String.valueOf(ex.getMessage())); } } //According to http://www.w3.org/TR/REC-xml/#syntax node values must not //contain the characters < or &. Also the > character should be escaped. if (this.content.contains("&") || this.content.contains("<") || this.content.contains(">")) { xml.append("<![CDATA["); xml.append(this.content.replaceAll("]]>", "]]]]><![CDATA[>")); xml.append("]]>"); } else { xml.append(this.content); } xml.append("</string>"); }