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.5.0.tar.gz
(19.6 kB
view details)
Built Distribution
bistring-0.5.0-py3-none-any.whl
(22.4 kB
view details)
File details
Details for the file bistring-0.5.0.tar.gz
.
File metadata
- Download URL: bistring-0.5.0.tar.gz
- Upload date:
- Size: 19.6 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.27.1 requests-toolbelt/0.9.1 tqdm/4.63.0 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac3f583d720d41fade1762894fe3b43711b75146d6230b1b9bfe23776774b8e8 |
|
MD5 | cb7f3a5026b047496242b53c78a3bf41 |
|
BLAKE2b-256 | 1d9105ebc772a7e5bbb456c07cb78655c715b5864083e59279f795bb0f5a83f0 |
File details
Details for the file bistring-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: bistring-0.5.0-py3-none-any.whl
- Upload date:
- Size: 22.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.63.0 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d01e9dc678ec5201007f636a1cd15f6fc77a6582a1ed666f7446ea38a51c6958 |
|
MD5 | 797c01c57be77921b762d21f3d1dbc1a |
|
BLAKE2b-256 | 29615ab43ce00eaeabc4314c5d93e3dd7b30ce97544c4b1717cc92ea6764b6cf |