Skip to main content

Bidirectionally transformed strings

Project description

The bistring library provides non-destructive versions of common string processing operations like normalization, case folding, and find/replace. Each bistring remembers the original string, and how its substrings map to substrings of the modified version.

For example:

>>> from bistring import bistr
>>> s = bistr('๐•ฟ๐–๐–Š ๐––๐–š๐–Ž๐–ˆ๐–, ๐–‡๐–—๐–”๐–œ๐–“ ๐ŸฆŠ ๐–๐–š๐–’๐–•๐–˜ ๐–”๐–›๐–Š๐–— ๐–™๐–๐–Š ๐–‘๐–†๐–Ÿ๐–ž ๐Ÿถ')
>>> s = s.normalize('NFKD')     # Unicode normalization
>>> s = s.casefold()            # Case-insensitivity
>>> s = s.replace('๐ŸฆŠ', 'fox')  # Replace emoji with text
>>> s = s.replace('๐Ÿถ', 'dog')
>>> s = s.sub(r'[^\w\s]+', '')  # Strip everything but letters and spaces
>>> s = s[:19]                  # Extract a substring
>>> s.modified                  # The modified substring, after changes
'the quick brown fox'
>>> s.original                  # The original substring, before changes
'๐•ฟ๐–๐–Š ๐––๐–š๐–Ž๐–ˆ๐–, ๐–‡๐–—๐–”๐–œ๐–“ ๐ŸฆŠ'

This allows you to perform very aggressive text processing completely invisibly.

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

bistring-0.3.0.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

bistring-0.3.0-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file bistring-0.3.0.tar.gz.

File metadata

  • Download URL: bistring-0.3.0.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4

File hashes

Hashes for bistring-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8a284615072586957f04631a362b5b94a14389a0d9c1985ab57414c4ca25f630
MD5 6bb46a64284fdea9cf221c4e57c15c36
BLAKE2b-256 5276b0b5b78a8d92549606a141e22cade0220ba24f4d48de59a5e683e939dabb

See more details on using hashes here.

File details

Details for the file bistring-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: bistring-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4

File hashes

Hashes for bistring-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c4159c4d11b8db06ca7df3fad18828ea8699fa4929d5ac2b7595f93ddf06f0cc
MD5 5b375b08bf837ca72f448973e7660eac
BLAKE2b-256 c74dea7f5b710a0efa4eb8cdb00cd7b4ebfbda0656bbef8552218477c493b3d9

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