Guest User

Untitled

a guest
Jul 16th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import sublime
  2. import sublime_plugin
  3. import re
  4.  
  5. class DartCodeUnitCommand(sublime_plugin.TextCommand):
  6. def run(self, edit):
  7. rd = re.compile(r'r?([\'"])(.)\1\.codeUnitAt\(0\)');
  8. for selection in self.view.sel():
  9. selectionText = self.view.substr(selection);
  10. matches = list(rd.finditer(selectionText))
  11. if (len(matches) > 0):
  12. for match in reversed(matches):
  13. matchText = match.group(0)
  14. originalLength = len(matchText)
  15. replacement = str(hex(ord(match.group(2)))) + " /*'" + match.group(2) + "'*/"
  16. selectionText = (selectionText[:match.start(0)] +
  17. replacement +
  18. selectionText[match.end(0):])
  19. self.view.replace(edit, selection, selectionText)
  20. else:
  21. self.view.replace(edit, selection, selectionText + "/*NO*/");
  22.  
  23. # Converts: 'x'.codeUnitAt(0)
  24. # To: 0x58 /*'x'*/
  25. # Works with any single-character single-line string.
  26. #
  27. # Add to User keymap:
  28. # { "keys": ["shift+ctrl+c"], "command": "dart_code_unit" },
Add Comment
Please, Sign In to add comment