Skip to main content

An implementation of the Unicode algorithm for breaking code point sequences into extended grapheme clusters as specified in UAX #29

Project description

pyuegc

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 15.0 of the Unicode standard (released on September 13, 2022). It has been thoroughly tested against the Unicode test file.

Installation

The easiest method to install is using pip:

pip install pyuegc

UCD version

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

>>> from pyuegc import UCD_VERSION
>>> UCD_VERSION
'15.0.0'

Example usage

from pyuegc import EGC

for s in ["e\u0301le\u0300ve", "Z̷̳̎a̸̛ͅl̷̻̇g̵͉̉o̸̰͒", "기운찰만하다"]:
    egc = EGC(s)
    print(f"{len(s):>2}, {len(egc)}: {egc}")

# Output
#  7, 5: ['é', 'l', 'è', 'v', 'e']
# 20, 5: ['Z̷̳̎', 'a̸̛ͅ', 'l̷̻̇', 'g̵͉̉', 'o̸̰͒']
# 15, 6: ['기', '운', '찰', '만', '하', '다']


s = "ai\u0302ne\u0301e"  # aînée
print("".join(reversed(s)))
print("".join(reversed(EGC(s))))

# Output
# éen̂ia -> wrong (diacritics are messed up)
# eénîa -> right (regardless of the Unicode normalization form)

Related resources

This implementation is based on the following resources:

Licenses

The code is available under the 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-15.0.0.tar.gz (66.8 kB view details)

Uploaded Source

File details

Details for the file pyuegc-15.0.0.tar.gz.

File metadata

  • Download URL: pyuegc-15.0.0.tar.gz
  • Upload date:
  • Size: 66.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 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-15.0.0.tar.gz
Algorithm Hash digest
SHA256 256e1ad94382fe39b0d73547a8c8b66562ca6a058a37408f6446e1d15eb26f29
MD5 b3a892939a529b4afa0a1df3e05ad879
BLAKE2b-256 58b78e8dff6ad1459d88fab72260596d796a46dd2a8cbc1cef919c9280809c16

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