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.4.0.tar.gz
(24.4 kB
view details)
Built Distribution
bistring-0.4.0-py3-none-any.whl
(22.2 kB
view details)
File details
Details for the file bistring-0.4.0.tar.gz
.
File metadata
- Download URL: bistring-0.4.0.tar.gz
- Upload date:
- Size: 24.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7bc8d123958b343677942e7fbc41b67e5cdb432c91852cbcff851a3430e43d8 |
|
MD5 | d72f9cee1333953e3a06ab3192f7474d |
|
BLAKE2b-256 | b19a87d8ccce6cbfb3434e9c4a58a14060716dc040177e4162d2c7cc2ada5ce2 |
File details
Details for the file bistring-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: bistring-0.4.0-py3-none-any.whl
- Upload date:
- Size: 22.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9d8a723d905b9f921992203872b07b2ac96845791f979ca145cee2a67b4f497 |
|
MD5 | 7db0488ae6e620309bc094ff033a3bb1 |
|
BLAKE2b-256 | 817f2a8f3a5d82a6c096440ef3d35835576ac73c77e519e86252ee01f5c344dd |