Files
SwiftLint/Source/SwiftLintFramework/Extensions/String+XML.swift
T
Fabian Ehrentraud 2f8c54d3c7 uppercase XML
2016-12-13 12:33:05 -08:00

26 lines
650 B
Swift

//
// String+XML.swift
// SwiftLint
//
// Created by Fabian Ehrentraud on 12/12/16.
// Copyright © 2016 Realm. All rights reserved.
//
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
}
}