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.2.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

bistring-0.2-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bistring-0.2.tar.gz
  • Upload date:
  • Size: 18.4 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.3

File hashes

Hashes for bistring-0.2.tar.gz
Algorithm Hash digest
SHA256 d0c35e0e2962990ea82657efe8093b72f249b1844d1d22cdf23d13b965e8e538
MD5 d72e22390e0c194b47726c64fd34a6ac
BLAKE2b-256 a5aacee8037e34e63cfc5e2191f434796bf7c5b1792e100522b9323699644aad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bistring-0.2-py3-none-any.whl
  • Upload date:
  • Size: 21.8 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.3

File hashes

Hashes for bistring-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ea7b5db870ad00886e118d01d543eda04fbc24e4984d3603fd6557af6e6b7ca5
MD5 26d171b7e8e8c18b2dac004765636aee
BLAKE2b-256 9bf54c5c82796d88d25315422ccfa8880ff0489c37273815438f0fd6e901ee81

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