Skip to content

Commit

Permalink
v2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fgallaire committed Dec 27, 2016
1 parent ce52837 commit c83e868
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,38 @@ Or you can just use the ``cjkwrap.py`` file alone, nothing more needed!
Usage
-----

``cjklen()`` and ``cjkslices()`` to replace built-in ``len()`` and slicing::
``is_wide()`` to know if a char is double-width, ``cjklen()`` and ``cjkslices()`` to replace built-in ``len()`` and slicing::

>>> import cjkwrap
>>> cjkwrap.is_wide(u"c")
False
>>> cjkwrap.is_wide(u"長")
True
>>> cjkwrap.cjklen(u"最終的には良い長さ")
18
>>> head, tail = cjkwrap.cjkslices(u"最終的には良い長さ", 6)
>>> print head
>>> print(head)
最終的
>>> print tail
>>> print(tail)
には良い長さ

As ``cjklen()`` uses ``len()`` for non unicode stuff, you can safely do this::

>>> from cjkwrap import cjklen as len
>>> len(u"最終的には良い長さ")
18
>>> len('ascii string')
12
>>> len([1, 2, 3, 4])
4

``wrap()`` and ``fill()`` to replace the ones from the Python standard library::

>>> wrapped_cjk = cjkwrap.wrap(u"最終的に良いラッピング", 10)
>>> for line in wrapped_cjk: print line
>>> for line in wrapped_cjk: print(line)
...
最終的に良
いラッピン
>>> print cjkwrap.fill(u"最終的に良いラッピング", 10)
>>> print(cjkwrap.fill(u"最終的に良いラッピング", 10))
最終的に良
いラッピン
Expand All @@ -68,7 +70,7 @@ Mixed content is allowed::

>>> cjkwrap.cjklen(u"CJK 最終的には良い長さ")
22
>>> print cjkwrap.fill(u"CJK 最終的には良い長さ", 10)
>>> print(cjkwrap.fill(u"CJK 最終的には良い長さ", 10))
CJK 最終的
には良い長
Expand Down
2 changes: 1 addition & 1 deletion cjkwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

__version__ = '2.0'
__version__ = '2.1'

import textwrap
import unicodedata
Expand Down

0 comments on commit c83e868

Please sign in to comment.