escapeHtml function

String escapeHtml(
  1. String value
)

Escapes & < > " ' for text and attribute values.

Implementation

String escapeHtml(String value) {
  final out = StringBuffer();
  for (final unit in value.runes) {
    out.write(switch (unit) {
      0x26 => '&amp;',
      0x3C => '&lt;',
      0x3E => '&gt;',
      0x22 => '&quot;',
      0x27 => '&#039;',
      _ => String.fromCharCode(unit),
    });
  }
  return out.toString();
}