18 lines
509 B
Swift
18 lines
509 B
Swift
extension String {
|
|
func escapedForXML() -> String {
|
|
// & needs to go first, otherwise other replacements will be replaced again
|
|
let htmlEscapes = [
|
|
("&", "&"),
|
|
("\"", """),
|
|
("'", "'"),
|
|
(">", ">"),
|
|
("<", "<")
|
|
]
|
|
var newString = self
|
|
for (key, value) in htmlEscapes {
|
|
newString = newString.replacingOccurrences(of: key, with: value)
|
|
}
|
|
return newString
|
|
}
|
|
}
|