text method

String text (Object value)

Escape values for placement inside the contents of a HTML or XML element.

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 text(Object value) {
  if (value != null) {
    var s = value.toString().replaceAll("&", "&amp;");
    s = s.replaceAll("<", "&lt;");
    s = s.replaceAll(">", "&gt;");
    return s;
  } else {
    return "";
  }
}