splash/Sources/Splash/Extensions/Strings/String+HTMLEntities.swift

25 lines
522 B
Swift
Raw Normal View History

/**
* Splash
* Copyright (c) John Sundell 2019
* MIT license - see LICENSE.md
*/
import Foundation
internal extension StringProtocol {
func escapingHTMLEntities() -> String {
return String(flatMap { character -> String in
switch character {
case "&":
return "&"
case "<":
return "&lt;"
case ">":
return "&gt;"
default:
return String(character)
}
})
}
}