mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2025-02-17 01:11:36 +01:00
Decode/Encode xml characters in the Plist Editor
This commit is contained in:
parent
7dec627fb7
commit
c0fba39133
@ -174,9 +174,9 @@ extension String {
|
|||||||
return UnsafePointer<UInt8>(buffer)
|
return UnsafePointer<UInt8>(buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Escape XML special characthers such:
|
/// Encode XML special characthers such:
|
||||||
/// & as &, \ as ", ' as &apos, < as <, and > as >
|
/// & as &, \ as ", ' as &apos, < as <, and > as >
|
||||||
var escapingXMLCharacters: String {
|
var encodingXMLCharacters: String {
|
||||||
get {
|
get {
|
||||||
/*
|
/*
|
||||||
" "
|
" "
|
||||||
@ -192,13 +192,14 @@ extension String {
|
|||||||
s = s.replacingOccurrences(of: "'", with: "'")
|
s = s.replacingOccurrences(of: "'", with: "'")
|
||||||
s = s.replacingOccurrences(of: "<", with: "<")
|
s = s.replacingOccurrences(of: "<", with: "<")
|
||||||
s = s.replacingOccurrences(of: ">", with: ">")
|
s = s.replacingOccurrences(of: ">", with: ">")
|
||||||
|
print(s)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert XML characters such:
|
/// Decode XML characters such:
|
||||||
/// & to &, " to \ , ' to &apos, < to <, and > to >
|
/// & to &, " to \ , ' to &apos, < to <, and > to >
|
||||||
var convertingXMLCharacters: String {
|
var decodingXMLCharacters: String {
|
||||||
get {
|
get {
|
||||||
/*
|
/*
|
||||||
" "
|
" "
|
||||||
|
@ -50,7 +50,7 @@ func gConvertPENodeToPlist(node: PENode?) -> String {
|
|||||||
plist = xml1Header + "\n" + gSerializeNodeToPlist(node: node!, file: "", indentation: 0) + xml1Footer
|
plist = xml1Header + "\n" + gSerializeNodeToPlist(node: node!, file: "", indentation: 0) + xml1Footer
|
||||||
}
|
}
|
||||||
} else if type == .String {
|
} 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 {
|
} else if type == .Data {
|
||||||
let data = ro.value as! NSData
|
let data = ro.value as! NSData
|
||||||
let strBase64 : String = (data as Data).base64EncodedString(options: .endLineWithLineFeed)
|
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 type == .Dictionary {
|
||||||
if !isRoot {
|
if !isRoot {
|
||||||
if node.peparent != nil && node.peparent!.tagdata!.type != .Array {
|
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 {
|
} else {
|
||||||
str = "<dict>\n"
|
str = "<dict>\n"
|
||||||
@ -120,7 +120,7 @@ func gSerializeNodeToPlist(node: PENode, file: String, indentation: Int) -> Stri
|
|||||||
}
|
}
|
||||||
} else if type == .Array {
|
} else if type == .Array {
|
||||||
if !isRoot {
|
if !isRoot {
|
||||||
str += indent + "<key>" + node.tagdata!.key + "</key>" + "\n"
|
str += indent + "<key>" + node.tagdata!.key.encodingXMLCharacters + "</key>" + "\n"
|
||||||
} else {
|
} else {
|
||||||
str = "<array>\n"
|
str = "<array>\n"
|
||||||
}
|
}
|
||||||
@ -153,14 +153,14 @@ func gSerializeNodeToPlist(node: PENode, file: String, indentation: Int) -> Stri
|
|||||||
<string>hi</string>
|
<string>hi</string>
|
||||||
*/
|
*/
|
||||||
if node.peparent!.tagdata!.type != .Array {
|
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 {
|
} else if isRoot {
|
||||||
str = str + indent + "<key>" + localizedNewItem + "</key>" + "\n"
|
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 {
|
} else if type == .Data {
|
||||||
if node.peparent!.tagdata!.type != .Array {
|
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 {
|
} else if isRoot {
|
||||||
str = str + indent + "<key>" + localizedNewItem + "</key>" + "\n"
|
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"
|
str = str + indent + "<data>" + strBase64 + "</data>" + "\n"
|
||||||
} else if type == .Date {
|
} else if type == .Date {
|
||||||
if node.peparent!.tagdata!.type != .Array {
|
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 {
|
} else if isRoot {
|
||||||
str = str + indent + "<key>" + localizedNewItem + "</key>" + "\n"
|
str = str + indent + "<key>" + localizedNewItem + "</key>" + "\n"
|
||||||
}
|
}
|
||||||
str = str + indent + "<date>" + utcDateToString(node.tagdata!.value as! Date) + "</date>" + "\n"
|
str = str + indent + "<date>" + utcDateToString(node.tagdata!.value as! Date) + "</date>" + "\n"
|
||||||
} else if type == .Number {
|
} else if type == .Number {
|
||||||
if node.peparent!.tagdata!.type != .Array {
|
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 {
|
} else if isRoot {
|
||||||
str = str + indent + "<key>" + localizedNewItem + "</key>" + "\n"
|
str = str + indent + "<key>" + localizedNewItem + "</key>" + "\n"
|
||||||
}
|
}
|
||||||
@ -190,7 +190,7 @@ func gSerializeNodeToPlist(node: PENode, file: String, indentation: Int) -> Stri
|
|||||||
}
|
}
|
||||||
} else if type == .Bool {
|
} else if type == .Bool {
|
||||||
if node.peparent!.tagdata!.type != .Array {
|
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 {
|
} else if isRoot {
|
||||||
str = str + indent + "<key>" + localizedNewItem + "</key>" + "\n"
|
str = str + indent + "<key>" + localizedNewItem + "</key>" + "\n"
|
||||||
}
|
}
|
||||||
|
@ -331,10 +331,10 @@ final class PlistParser: NSObject, XMLParserDelegate {
|
|||||||
self.goback()
|
self.goback()
|
||||||
break
|
break
|
||||||
case "key":
|
case "key":
|
||||||
self.currentNode?.tagdata?.key = value?.escapingXMLCharacters ?? ""
|
self.currentNode?.tagdata?.key = value?.decodingXMLCharacters ?? ""
|
||||||
break
|
break
|
||||||
case "string":
|
case "string":
|
||||||
self.currentNode?.tagdata?.value = value!.escapingXMLCharacters
|
self.currentNode?.tagdata?.value = value!.decodingXMLCharacters
|
||||||
self.currentNode?.tagdata?.type = .String
|
self.currentNode?.tagdata?.type = .String
|
||||||
self.goback()
|
self.goback()
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user