README.rst
1CJKwrap
2=======
3
4**CJKwrap** is a library for wrapping and filling CJK text.
5
6CJKwrap fix the issue24665 because Python 2 will stay broken forever:
7https://bugs.python.org/issue24665.
8
9CJKwrap support **both** Python 2 (2.6 and above) and Python 3 (3.3 and above).
10
11CJKwrap is developed by Florent Gallaire fgallaire@gmail.com.
12
13Website: http://fgallaire.github.io/cjkwrap.
14
15Download and Install
16--------------------
17
18To install the last stable version from PyPI::
19
20 $ sudo pip install cjkwrap
21
22To install the development version from GitHub::
23
24 $ git clone https://github.com/fgallaire/cjkwrap
25 $ cd cjkwrap
26 $ sudo python setup.py install
27
28Or you can just use the ``cjkwrap.py`` file alone, nothing more needed!
29
30Usage
31-----
32
33``is_wide()`` to know if a char is double-width, ``cjklen()`` and ``cjkslices()`` to replace built-in ``len()`` and slicing::
34
35 >>> import cjkwrap
36 >>> cjkwrap.is_wide(u"c")
37 False
38 >>> cjkwrap.is_wide(u"長")
39 True
40 >>> cjkwrap.cjklen(u"最終的には良い長さ")
41 18
42 >>> head, tail = cjkwrap.cjkslices(u"最終的には良い長さ", 6)
43 >>> print(head)
44 最終的
45 >>> print(tail)
46 には良い長さ
47
48As ``cjklen()`` uses ``len()`` for non unicode stuff, you can safely do this::
49
50 >>> from cjkwrap import cjklen as len
51 >>> len(u"最終的には良い長さ")
52 18
53 >>> len([1, 2, 3, 4])
54 4
55
56``wrap()`` and ``fill()`` to replace the ones from the Python standard library::
57
58 >>> wrapped_cjk = cjkwrap.wrap(u"最終的に良いラッピング", 10)
59 >>> for line in wrapped_cjk: print(line)
60 ...
61 最終的に良
62 いラッピン
63 グ
64 >>> print(cjkwrap.fill(u"最終的に良いラッピング", 10))
65 最終的に良
66 いラッピン
67 グ
68
69Mixed content is allowed::
70
71 >>> cjkwrap.cjklen(u"CJK 最終的には良い長さ")
72 22
73 >>> print(cjkwrap.fill(u"CJK 最終的には良い長さ", 10))
74 CJK 最終的
75 には良い長
76 さ
77
78License
79-------
80
81CJKwrap files are released under the GNU LGPLv3 or above license.
82
83CJKwrap codebase from textwrap by Greg Ward (gward@python.net) under the Python license.
84