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