Wrap Lambda function in a struct to avoid crash in Mirror

This commit is contained in:
Adam Fowler
2021-03-15 14:46:40 +00:00
parent 3559faac61
commit 978b14a96a
4 changed files with 86 additions and 24 deletions

View File

@@ -0,0 +1,23 @@
extension String {
private static let htmlEscapedCharacters: [Character: String] = [
"<": "&lt;",
">": "&gt;",
"&": "&amp;",
]
/// HTML escape string. Replace '<', '>' and '&' with HTML escaped versions
func htmlEscape() -> String {
var newString = ""
newString.reserveCapacity(self.count)
// currently doing this by going through each character could speed
// this us by treating as an array of UInt8's
for c in self {
if let replacement = Self.htmlEscapedCharacters[c] {
newString += replacement
} else {
newString.append(c)
}
}
return newString
}
}