roberteldersoftwarediff.py 文件源码

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

项目:roberteldersoftwarediff 作者: RobertElderSoftware 项目源码 文件源码
def make_character_presentable(c, rp):
    if len(c) == 0:
        return c, 0  #  The result of an ignored failed decode from an invalid character.

    #  A character at this point should be a list of integers.
    for b in c:
        assert(type(b) == int)
    if rp.pretty_output:
        if len(c) == 1 and ((c[0] > 31 and c[0] < 127) or c[0] == ord('\t')):
            #  Standard ascii character
            if c[0] == ord('\t'):
                return [ord(u" "),ord(u" "),ord(u" "),ord(u" ")], 4
            else:
                return [c[0]], 1
        else:
            #  Extended ASCII characer or multi-byte character.
            rtn = []
            for byte in c:
                rtn += [py23_ord(b) for b in (b"\\x" + as_byte_string(format(byte, '02X'), rp.output_encoding, "internal"))]
            return rtn, len(rtn)
    else:
        #  This is not precise at all, but it is the best that can be done
        char_as_unicode = e_decode(int_array_as_byte_string(c), rp.output_encoding, "internal")
        if len(char_as_unicode) == 0:
            return [], 0  #  Happens sometimes due to decode failure on invalid characters. 
        east_asian_width = get_east_asian_width(char_as_unicode)
        replacement_chars = get_replacement_char(char_as_unicode)
        if replacement_chars is None:
            return c, east_asian_width
        else:
            ls = [get_east_asian_width(c) for c in replacement_chars]
            return [py23_ord(b) for b in as_byte_string(replacement_chars, rp.output_encoding, "internal")], sum(ls)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号