Skip to main content

Module text

Module text 

Source
Expand description

String utility functions for Unicode-safe text manipulation.

Functions§

estimate_tokens
Rough token count estimate: 1 token ≈ 4 Unicode scalar values.
truncate_chars
Borrow a prefix of s that is at most max_chars Unicode scalar values long.
truncate_to_bytes
Truncate s to at most max_bytes bytes, preserving UTF-8 char boundaries.
truncate_to_bytes_ref
Borrow a prefix of s that fits within max_bytes bytes.
truncate_to_chars
Truncate a string to at most max_chars Unicode scalar values.