pCommon.py 文件源码

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

项目:crossplatform_iptvplayer 作者: j00zek 项目源码 文件源码
def getNormalizeStr(txt, idx=None):
        POLISH_CHARACTERS = {u'?':u'a', u'?':u'c', u'?':u'?', u'?':u'l', u'?':u'n', u'ó':u'o', u'?':u's', u'?':u'z', u'?':u'z',
                             u'?':u'A', u'?':u'C', u'?':u'E', u'?':u'L', u'?':u'N', u'Ó':u'O', u'?':u'S', u'?':u'Z', u'?':u'Z',
                             u'á':u'a', u'é':u'e', u'í':u'i', u'ñ':u'n', u'ó':u'o', u'ú':u'u', u'ü':u'u',
                             u'Á':u'A', u'É':u'E', u'Í':u'I', u'Ñ':u'N', u'Ó':u'O', u'Ú':u'U', u'Ü':u'U',
                            }
        txt = txt.decode('utf-8')
        if None != idx: txt = txt[idx]
        nrmtxt = unicodedata.normalize('NFC', txt)
        ret_str = []
        for item in nrmtxt:
            if ord(item) > 128:
                item = POLISH_CHARACTERS.get(item)
                if item: ret_str.append(item)
            else: # pure ASCII character
                ret_str.append(item)
        return ''.join(ret_str).encode('utf-8')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号