Files
SwiftLint/Source/SwiftLintFramework/Extensions/String+XML.swift
T
2025-10-08 08:12:05 +02:00

20 lines
529 B
Swift

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