Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sublime
- import sublime_plugin
- import re
- class DartCodeUnitCommand(sublime_plugin.TextCommand):
- def run(self, edit):
- rd = re.compile(r'r?([\'"])(.)\1\.codeUnitAt\(0\)');
- for selection in self.view.sel():
- selectionText = self.view.substr(selection);
- matches = list(rd.finditer(selectionText))
- if (len(matches) > 0):
- for match in reversed(matches):
- matchText = match.group(0)
- originalLength = len(matchText)
- replacement = str(hex(ord(match.group(2)))) + " /*'" + match.group(2) + "'*/"
- selectionText = (selectionText[:match.start(0)] +
- replacement +
- selectionText[match.end(0):])
- self.view.replace(edit, selection, selectionText)
- else:
- self.view.replace(edit, selection, selectionText + "/*NO*/");
- # Converts: 'x'.codeUnitAt(0)
- # To: 0x58 /*'x'*/
- # Works with any single-character single-line string.
- #
- # Add to User keymap:
- # { "keys": ["shift+ctrl+c"], "command": "dart_code_unit" },
Add Comment
Please, Sign In to add comment