From c83e86861eac9960236ca8d7644ea3abdf8437e3 Mon Sep 17 00:00:00 2001 From: Florent Gallaire Date: Tue, 27 Dec 2016 06:11:18 +0100 Subject: [PATCH] v2.1 --- README.rst | 18 ++++++++++-------- cjkwrap.py | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.rst b/README.rst index 9ada289..4b958d9 100644 --- a/README.rst +++ b/README.rst @@ -30,15 +30,19 @@ 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:: @@ -46,20 +50,18 @@ 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)) 最終的に良 いラッピン グ @@ -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 最終的 には良い長 さ diff --git a/cjkwrap.py b/cjkwrap.py index 388540b..931e1f1 100644 --- a/cjkwrap.py +++ b/cjkwrap.py @@ -23,7 +23,7 @@ along with this program. If not, see . """ -__version__ = '2.0' +__version__ = '2.1' import textwrap import unicodedata