rtf.py 文件源码

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

项目:chalktalk_docs 作者: loremIpsum1771 项目源码 文件源码
def _escape_text(self, text):
        # empty strings, should give a small performance improvment
        if not text:
            return u''

        # escape text
        text = self._escape(text)

        buf = []
        for c in text:
            cn = ord(c)
            if cn < (2**7):
                # ASCII character
                buf.append(str(c))
            elif (2**7) <= cn < (2**16):
                # single unicode escape sequence
                buf.append(u'{\\u%d}' % cn)
            elif (2**16) <= cn:
                # RTF limits unicode to 16 bits.
                # Force surrogate pairs
                buf.append(u'{\\u%d}{\\u%d}' % _surrogatepair(cn))

        return u''.join(buf).replace(u'\n', u'\\par\n')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号