Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fgallaire/cjkwrap
NEW HOME ON GITLAB
https://github.com/fgallaire/cjkwrap
Last synced: 10 days ago
JSON representation
NEW HOME ON GITLAB
- Host: GitHub
- URL: https://github.com/fgallaire/cjkwrap
- Owner: fgallaire
- Created: 2016-09-04T03:17:02.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-21T16:56:13.000Z (over 6 years ago)
- Last Synced: 2024-10-07T10:09:31.363Z (about 1 month ago)
- Language: Python
- Homepage: https://gitlab.com/fgallaire/cjkwrap
- Size: 619 KB
- Stars: 16
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: licenses/COPYING
Awesome Lists containing this project
README
CJKwrap
=======**CJKwrap** is a library for wrapping and filling CJK text.
CJKwrap fix the issue24665 because Python 2 will stay broken forever:
https://bugs.python.org/issue24665.CJKwrap support **both** Python 2 (2.6 and above) and Python 3 (3.3 and above).
CJKwrap is developed by Florent Gallaire [email protected].
Website: http://fgallaire.github.io/cjkwrap.
Download and Install
--------------------To install the last stable version from PyPI::
$ sudo pip install cjkwrap
To install the development version from GitHub::
$ git clone https://github.com/fgallaire/cjkwrap
$ cd cjkwrap
$ sudo python setup.py installOr you can just use the ``cjkwrap.py`` file alone, nothing more needed!
Usage
-----``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(tail)
には良い長さAs ``cjklen()`` uses ``len()`` for non unicode stuff, you can safely do this::
>>> from cjkwrap import cjklen as len
>>> len(u"最終的には良い長さ")
18
>>> 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)
...
最終的に良
いラッピン
グ
>>> print(cjkwrap.fill(u"最終的に良いラッピング", 10))
最終的に良
いラッピン
グMixed content is allowed::
>>> cjkwrap.cjklen(u"CJK 最終的には良い長さ")
22
>>> print(cjkwrap.fill(u"CJK 最終的には良い長さ", 10))
CJK 最終的
には良い長
さLicense
-------CJKwrap files are released under the GNU LGPLv3 or above license.
CJKwrap codebase from textwrap by Greg Ward ([email protected]) under the Python license.