attr static method

String attr(
  1. Object? value
)

Escape values for placement inside a HTML or XML attribute.

Returns a string where all characters &, <, >, ' and " in the string representation of value is replaced by its HTML entities. The string representation is produced by invoking toString on the value.

If value is null, the empty string is returned.

Implementation

static String attr(Object? value) {
  if (value != null) {
    var s = value.toString().replaceAll('&', '&amp;');
    s = s.replaceAll('<', '&lt;');
    s = s.replaceAll('>', '&gt;');
    s = s.replaceAll("'", '&apos;');
    s = s.replaceAll('"', '&quot;');
    return s;
  } else {
    return '';
  }
}