String _escape()

in tool/codeviewer_cli/prehighlighter.dart [384:405]


String _escape(String text) {
  final escapedText = StringBuffer();

  for (final char in text.runes) {
    if (char < 0x20 ||
        char >= 0x7F ||
        char == 0x22 ||
        char == 0x24 ||
        char == 0x27 ||
        char == 0x5C) {
      if (char <= 0xffff) {
        escapedText.write('\\u${_encodeAndPad(char)}');
      } else {
        escapedText.write('\\u{${_encode(char)}}');
      }
    } else {
      escapedText.write(String.fromCharCode(char));
    }
  }

  return escapedText.toString();
}