mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
26 lines
650 B
Swift
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 = [
|
|
("&", "&"),
|
|
("\"", """),
|
|
("'", "'"),
|
|
(">", ">"),
|
|
("<", "<")
|
|
]
|
|
var newString = self
|
|
for (key, value) in htmlEscapes {
|
|
newString = newString.replacingOccurrences(of: key, with: value)
|
|
}
|
|
return newString
|
|
}
|
|
}
|