escape function

String escape(
  1. String string
)

Converts the characters "&", "<", ">", '"', and "'" in string to their corresponding HTML entities.

Implementation

String escape(String string) {
  return string
      .replaceAll(RegExp(r'&'), '&amp;')
      .replaceAll(RegExp(r'<'), '&lt;')
      .replaceAll(RegExp(r'>'), '&gt;')
      .replaceAll(RegExp(r'"'), '&quot;')
      .replaceAll(RegExp(r"'"), '&#x27;');
}