Skip to main content

A lightweight converter between hankaku(half-width) and zenkaku(full-width) characters

Project description

https://badge.fury.io/py/mojimoji.png https://travis-ci.org/studio-ousia/mojimoji.png?branch=master

A lightweight converter between hankaku(half-width) and zenkaku(full-width) characters.

Installation

$ pip install mojimoji

Examples

Zenkaku to Hankaku

>>> import mojimoji
>>> print mojimoji.zen_to_han(u'アイウabc012')
アイウabc012
>>> print mojimoji.zen_to_han(u'アイウabc012', kana=False)
アイウabc012
>>> print mojimoji.zen_to_han(u'アイウabc012', digit=False)
アイウabc012
>>> print mojimoji.zen_to_han(u'アイウabc012', ascii=False)
アイウabc012

Hankaku to Zenkaku

>>> import mojimoji
>>> print mojimoji.han_to_zen(u'アイウabc012')
アイウabc012
>>> print mojimoji.han_to_zen(u'アイウabc012', kana=False)
アイウabc012
>>> print mojimoji.han_to_zen(u'アイウabc012', digit=False)
アイウabc012
>>> print mojimoji.han_to_zen(u'アイウabc012', ascii=False)
アイウabc012

Benchmarks

Library versions

Results

In [19]: s = u'ABCDEFG012345' * 10

In [20]: %time for n in range(1000000): mojimoji.zen_to_han(s)
CPU times: user 2.86 s, sys: 0.10 s, total: 2.97 s
Wall time: 2.88 s

In [21]: %time for n in range(1000000): unicodedata.normalize('NFKC', s)
CPU times: user 5.43 s, sys: 0.12 s, total: 5.55 s
Wall time: 5.44 s

In [22]: %time for n in range(1000000): zenhan.z2h(s)
CPU times: user 69.18 s, sys: 0.11 s, total: 69.29 s
Wall time: 69.48 s

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

mojimoji-0.0.5.tar.gz (34.4 kB view details)

Uploaded Source

File details

Details for the file mojimoji-0.0.5.tar.gz.

File metadata

  • Download URL: mojimoji-0.0.5.tar.gz
  • Upload date:
  • Size: 34.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mojimoji-0.0.5.tar.gz
Algorithm Hash digest
SHA256 341646869d88ba616a8a29e9c0680488c3ec37208f5aea7221e9ee13d1b08a41
MD5 5eb74101d125e981b9c2a2897ec7a8dd
BLAKE2b-256 b8d8b8bd7599f2eaa6bb370496160f70bb163cd0f5c23558df3a21a830aec833

See more details on using hashes here.

Supported by

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