def detect(self, begin_line, end_line):
begin_line = int(begin_line)
end_line = int(end_line)
begin_point = self.view.text_point(begin_line + 1, 0)
end_point = self.view.text_point(end_line, 0) - 1
region = sublime.Region(begin_point, end_point)
content = self.get_text(region)
if not content:
return
detector = UniversalDetector()
detector.feed(content)
detector.close()
encoding = detector.result['encoding']
confidence = detector.result['confidence']
encoding = encoding.upper()
if confidence < SETTINGS['confidence'] or encoding in SKIP_ENCODINGS:
return
self.view.run_command('convert_text_to_utf8', {'begin_line': begin_line, 'end_line': end_line, 'encoding': encoding})
评论列表
文章目录