Skip to main content

An implementation of the Unicode algorithm for breaking code point sequences into extended grapheme clusters as specified in UAX #29, “Unicode Text Segmentation”. This library supports version 14.0 of the Unicode Standard.

Project description

pyuegc

PyPI Version PyPI License

An implementation of the Unicode algorithm for breaking strings of text (i.e., code point sequences) into extended grapheme clusters (“user-perceived characters”) as specified in UAX #29, “Unicode Text Segmentation”. This package supports version 14.0 of the Unicode Standard (released September 14, 2021). It has been successfully tested against the Unicode test file.

Installation

pip install pyuegc

UCD version

To get the version of the Unicode character database currently used:

>>> from pyuegc import UCD_VERSION
>>> UCD_VERSION
'14.0.0'

Example usage

>>> from pyuegc import EGC
>>> len("e\u0301le\u0300ve")
7
>>> len(EGC("e\u0301le\u0300ve"))
5
>>> EGC("e\u0301le\u0300ve")
['é', 'l', 'è', 'v', 'e']
>>>
>>> s = "Z̸͕̪̆᷾᷾︣̌͊̕͝a̸̛͎ͭ͛̉᷆̿̂̚l̸̨̧̛̹̪̦̞̳ͧͬ̈́̽͜ǵ̶̢̛͓᷿̼̱̗̳̏︠o̵̘͓̣͚̍̎͆ͣ︡̓̓̅͠"
>>> len(s)
67
>>> clusters = EGC(s)
>>> clusters
['Z̸͕̪̆᷾᷾︣̌͊̕͝', 'a̸̛͎ͭ͛̉᷆̿̂̚', 'l̸̨̧̛̹̪̦̞̳ͧͬ̈́̽͜', 'ǵ̶̢̛͓᷿̼̱̗̳̏︠', 'o̵̘͓̣͚̍̎͆ͣ︡̓̓̅͠']
>>> len(clusters)
5
>>> s[:2]
'Z̆'
>>> "".join(clusters[:2])
'Z̸͕̪̆᷾᷾︣̌͊̕͝a̸̛͎ͭ͛̉᷆̿̂̚'
>>> 
>>> s = "기운찰만하다"
>>> len(s)
15
>>> clusters = EGC(s)
>>> clusters
['기', '운', '찰', '만', '하', '다']
>>> len(clusters)
6

References

Licenses

The pyuegc library is released under an MIT license.

Usage of Unicode data files is governed by the Unicode Terms of Use, a copy of which is included as UNICODE-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

pyuegc-14.0.0rc1.tar.gz (59.0 kB view details)

Uploaded Source

File details

Details for the file pyuegc-14.0.0rc1.tar.gz.

File metadata

  • Download URL: pyuegc-14.0.0rc1.tar.gz
  • Upload date:
  • Size: 59.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for pyuegc-14.0.0rc1.tar.gz
Algorithm Hash digest
SHA256 cbf9b918d4efaefb01652c426dada8d267639184dbdaf622d684f190e3d45b22
MD5 1dadb9ea41b907924aea3bd18086c225
BLAKE2b-256 580c8267ca00cd6b133e071d2a275da158ec98bb217480beb5089d4a6c427c05

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