Skip to main content

CJKwrap is a library for wrapping and filling CJK text. Fix Python issue24665

Project description

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 fgallaire@gmail.com.

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 install

Or 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 (gward@python.net) under the Python license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

CJKwrap-2.1.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

CJKwrap-2.1-py2.py3-none-any.whl (4.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file CJKwrap-2.1.tar.gz.

File metadata

  • Download URL: CJKwrap-2.1.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for CJKwrap-2.1.tar.gz
Algorithm Hash digest
SHA256 b3a53cc3ad4d1eb46164beb18baa0363317826cd382fcf147b491c16d7cee7a4
MD5 f228ec82a27d8932807226898c7642df
BLAKE2b-256 e6b1e51f135ac1598a5a95593161c4c52359e9be08fe87b8566a4c06530f573c

See more details on using hashes here.

File details

Details for the file CJKwrap-2.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for CJKwrap-2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4e398dfe8e5d123f5c5dc1d6c20d70fc2aa512cd65d02fd0afb4f8efd7d29306
MD5 db6978d919bb3728c5f9ae23bc0c9e28
BLAKE2b-256 511343c336399b955ff76df0d9edb88762441f35910a56adff9adefa2db0c9b0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page