escape function

String escape(
  1. String str
)

replace <, >, &, ' and " with HTML entities

Implementation

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