escape function
replace <
, >
, &
, '
and "
with HTML entities
Implementation
String escape(String str) {
return (str
.replaceAll(new RegExp(r'&'), '&')
.replaceAll(new RegExp(r'"'), '"')
.replaceAll(new RegExp(r"'"), ''')
.replaceAll(new RegExp(r'<'), '<')
.replaceAll(new RegExp(r'>'), '>'));
}