keytab_escape.dart 577 B

123456789101112131415161718192021
  1. final _esc = String.fromCharCode(0x1b);
  2. String keytabUnescape(String str) {
  3. str = str
  4. .replaceAll(r'\E', _esc)
  5. .replaceAll(r'\\', '\\')
  6. .replaceAll(r'\"', '\"')
  7. .replaceAll(r'\t', '\t')
  8. .replaceAll(r'\r', '\r')
  9. .replaceAll(r'\n', '\n')
  10. .replaceAll(r'\b', '\b');
  11. final hexPattern = RegExp(r'\\x([0-9a-fA-F][0-9a-fA-F])');
  12. str = str.replaceAllMapped(hexPattern, (match) {
  13. final hexString = match.group(1);
  14. final hexValue = int.parse(hexString, radix: 16);
  15. return String.fromCharCode(hexValue);
  16. });
  17. return str;
  18. }