escape function

String escape(
  1. String str
)

Returns str with all whitespace characters represented as their escape sequences.

Backslash characters are escaped as \\

Implementation

String escape(String str) {
  str = str.replaceAll('\\', r'\\');
  return str.replaceAllMapped(_escapeRegExp, (match) {
    var mapped = _escapeMap[match[0]];
    if (mapped != null) return mapped;
    return _getHexLiteral(match[0]!);
  });
}