unicode-segmentation-rs provides Python bindings for the Rust `unicode-segmentation` and `unicode-width` crates, offering robust Unicode text segmentation (grapheme clusters, words, sentences) and display width calculation according to Unicode standards. It is currently at version 0.2.4 and is an actively maintained library, with updates often tied to new Unicode standard releases in its underlying Rust dependencies.
pip install unicode-segmentation-rsVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage for grapheme, word, and sentence segmentation, as well as calculating the display width of a string.
Always pass `is_extended=True` to `graphemes()` and `grapheme_indices()` unless you specifically require legacy grapheme clustering behavior.
Iterate over the results of segmentation functions (e.g., `for grapheme in unicode_segmentation_rs.graphemes(text):`) rather than attempting direct string indexing with arbitrary offsets.
Ensure input strings are valid Unicode where possible. For critical applications, implement robust error handling around calls to `unicode_segmentation_rs` functions, especially with untrusted input.
`len(unicode_segmentation_rs.graphemes(my_string, is_extended=True))` will provide the count of user-perceived characters.
Always ensure that string inputs are correctly decoded from bytes if they originate from external sources (e.g., `my_bytes.decode('utf-8', errors='replace')`). The Python bindings should generally prevent direct exposure of raw byte-level issues unless the string itself is fundamentally corrupted.No dependency data recorded yet.