1. André Sintzoff
  2. thg-sintzoff

Commits

Yuya Nishihara  committed fc80c95

filedata: add method to guess encoding from its content (refs #3620)

  • Participants
  • Parent commits e9f68bd
  • Branches default

Comments (0)

Files changed (1)

File tortoisehg/hgqt/filedata.py

View file
  • Ignore whitespace
     def setTextEncoding(self, name):
         self._textencoding = fileencoding.canonname(name)
 
+    def detectTextEncoding(self):
+        ui = self._ctx._repo.ui
+        # use file content for better guess; diff may be mixed encoding or
+        # have immature multi-byte sequence
+        data = self.contents or self.diff or ''
+        fallbackenc = self._textencoding
+        self._textencoding = fileencoding.guessencoding(ui, data, fallbackenc)
+
     def _textToUnicode(self, s):
         return s.decode(self._textencoding, 'replace')