ConvertToUTF8.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:macos-st-packages 作者: zce 项目源码 文件源码
def detect(view, file_name, cnt):
    if not file_name or not os.path.exists(file_name) or os.path.getsize(file_name) == 0:
        return
    encoding = encoding_cache.pop(file_name)
    if encoding:
        sublime.set_timeout(lambda: init_encoding_vars(view, encoding, detect_on_fail=True), 0)
        return
    sublime.set_timeout(lambda: view.set_status('origin_encoding', 'Detecting encoding, please wait...'), 0)
    detector = UniversalDetector()
    fp = open(file_name, 'rb')
    for line in fp:
        # cut MS-Windows CR code
        line = line.replace(b'\r',b'')
        detector.feed(line)
        cnt -= 1
        if detector.done or cnt == 0:
            break
    fp.close()
    detector.close()
    encoding = detector.result['encoding']
    if encoding:
        encoding = encoding.upper()
    confidence = detector.result['confidence']
    sublime.set_timeout(lambda: check_encoding(view, encoding, confidence), 0)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号