| 1 | | /// `text` with the characters HTML gives meaning to replaced by entities, safe inside |
| 2 | | /// element content and double-quoted attributes. |
| 3 | 1515 | func escapingHTML(_ text: some StringProtocol) -> String { |
| 4 | 1515 | var escaped = "" |
| 5 | 1515 | escaped.reserveCapacity(text.utf8.count) |
| 6 | 14.6k | for character in text { |
| 7 | 14.6k | switch character { |
| 8 | 14.6k | case "&": escaped += "&" |
| 9 | 14.6k | case "<": escaped += "<" |
| 10 | 14.6k | case ">": escaped += ">" |
| 11 | 14.6k | case "\"": escaped += """ |
| 12 | 14.6k | default: escaped.append(character) |
| 13 | 14.7k | } |
| 14 | 14.7k | } |
| 15 | 1533 | return escaped |
| 16 | 1515 | } |