Revision: 258
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at July 6, 2006 18:00 by ndegruchy
Initial Code
# This recipe refers:
#
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/148061
import re
rx=re.compile(u\"([\\u2e80-\\uffff])\", re.UNICODE)
def cjkwrap(text, width, encoding=\"utf8\"):
return reduce(lambda line, word, width=width: \'%s%s%s\' %
(line,
[\' \',\'\\n\', \'\'][(len(line)-line.rfind(\'\\n\')-1
+ len(word.split(\'\\n\',1)[0] ) >= width) or
line[-1:] == \'\\0\' and 2],
word),
rx.sub(r\'\\1\\0 \', unicode(text,encoding)).split(\' \')
).replace(\'\\0\', \'\').encode(encoding)
Initial URL
Initial Description
Initial Title
Better Unicode Text Wrapping Function
Initial Tags
textmate, python
Initial Language
Python