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