Decode/Encode xml characters in the Plist Editor

This commit is contained in:
vectorsigma72 2020-06-03 16:41:01 +02:00
parent 7dec627fb7
commit c0fba39133
3 changed files with 16 additions and 15 deletions

View File

@ -174,9 +174,9 @@ extension String {
return UnsafePointer<UInt8>(buffer)
}
/// Escape XML special characthers such:
/// Encode XML special characthers such:
/// & as &amp, \ as &quot, ' as &apos, < as &lt, and > as &gt
var escapingXMLCharacters: String {
var encodingXMLCharacters: String {
get {
/*
" &quot;
@ -192,13 +192,14 @@ extension String {
s = s.replacingOccurrences(of: "'", with: "&apos;")
s = s.replacingOccurrences(of: "<", with: "&lt;")
s = s.replacingOccurrences(of: ">", with: "&gt;")
print(s)
return s
}
}
/// Convert XML characters such:
/// Decode XML characters such:
/// &amp to &, &quot to \ , ' to &apos, &lt to <, and &gt to >
var convertingXMLCharacters: String {
var decodingXMLCharacters: String {
get {
/*
" &quot;

View File

@ -50,7 +50,7 @@ func gConvertPENodeToPlist(node: PENode?) -> String {
plist = xml1Header + "\n" + gSerializeNodeToPlist(node: node!, file: "", indentation: 0) + xml1Footer
}
} else if type == .String {
plist = xml1Header + "\n" + "<string>" + (ro.value as! String) + "</string>" + "\n" + xml1Footer
plist = xml1Header + "\n" + "<string>" + (ro.value as! String).encodingXMLCharacters + "</string>" + "\n" + xml1Footer
} else if type == .Data {
let data = ro.value as! NSData
let strBase64 : String = (data as Data).base64EncodedString(options: .endLineWithLineFeed)
@ -89,7 +89,7 @@ func gSerializeNodeToPlist(node: PENode, file: String, indentation: Int) -> Stri
if type == .Dictionary {
if !isRoot {
if node.peparent != nil && node.peparent!.tagdata!.type != .Array {
str += indent + "<key>" + node.tagdata!.key + "</key>" + "\n"
str += indent + "<key>" + node.tagdata!.key.encodingXMLCharacters + "</key>" + "\n"
}
} else {
str = "<dict>\n"
@ -120,7 +120,7 @@ func gSerializeNodeToPlist(node: PENode, file: String, indentation: Int) -> Stri
}
} else if type == .Array {
if !isRoot {
str += indent + "<key>" + node.tagdata!.key + "</key>" + "\n"
str += indent + "<key>" + node.tagdata!.key.encodingXMLCharacters + "</key>" + "\n"
} else {
str = "<array>\n"
}
@ -153,14 +153,14 @@ func gSerializeNodeToPlist(node: PENode, file: String, indentation: Int) -> Stri
<string>hi</string>
*/
if node.peparent!.tagdata!.type != .Array {
str = str + indent + "<key>" + node.tagdata!.key + "</key>" + "\n"
str = str + indent + "<key>" + node.tagdata!.key.encodingXMLCharacters + "</key>" + "\n"
} else if isRoot {
str = str + indent + "<key>" + localizedNewItem + "</key>" + "\n"
}
str = str + indent + "<string>" + (node.tagdata!.value as! String) + "</string>" + "\n"
str = str + indent + "<string>" + (node.tagdata!.value as! String).encodingXMLCharacters + "</string>" + "\n"
} else if type == .Data {
if node.peparent!.tagdata!.type != .Array {
str = str + indent + "<key>" + node.tagdata!.key + "</key>" + "\n"
str = str + indent + "<key>" + node.tagdata!.key.encodingXMLCharacters + "</key>" + "\n"
} else if isRoot {
str = str + indent + "<key>" + localizedNewItem + "</key>" + "\n"
}
@ -169,14 +169,14 @@ func gSerializeNodeToPlist(node: PENode, file: String, indentation: Int) -> Stri
str = str + indent + "<data>" + strBase64 + "</data>" + "\n"
} else if type == .Date {
if node.peparent!.tagdata!.type != .Array {
str = str + indent + "<key>" + node.tagdata!.key + "</key>" + "\n"
str = str + indent + "<key>" + node.tagdata!.key.encodingXMLCharacters + "</key>" + "\n"
} else if isRoot {
str = str + indent + "<key>" + localizedNewItem + "</key>" + "\n"
}
str = str + indent + "<date>" + utcDateToString(node.tagdata!.value as! Date) + "</date>" + "\n"
} else if type == .Number {
if node.peparent!.tagdata!.type != .Array {
str = str + indent + "<key>" + node.tagdata!.key + "</key>" + "\n"
str = str + indent + "<key>" + node.tagdata!.key.encodingXMLCharacters + "</key>" + "\n"
} else if isRoot {
str = str + indent + "<key>" + localizedNewItem + "</key>" + "\n"
}
@ -190,7 +190,7 @@ func gSerializeNodeToPlist(node: PENode, file: String, indentation: Int) -> Stri
}
} else if type == .Bool {
if node.peparent!.tagdata!.type != .Array {
str = str + indent + "<key>" + node.tagdata!.key + "</key>" + "\n"
str = str + indent + "<key>" + node.tagdata!.key.encodingXMLCharacters + "</key>" + "\n"
} else if isRoot {
str = str + indent + "<key>" + localizedNewItem + "</key>" + "\n"
}

View File

@ -331,10 +331,10 @@ final class PlistParser: NSObject, XMLParserDelegate {
self.goback()
break
case "key":
self.currentNode?.tagdata?.key = value?.escapingXMLCharacters ?? ""
self.currentNode?.tagdata?.key = value?.decodingXMLCharacters ?? ""
break
case "string":
self.currentNode?.tagdata?.value = value!.escapingXMLCharacters
self.currentNode?.tagdata?.value = value!.decodingXMLCharacters
self.currentNode?.tagdata?.type = .String
self.goback()
break