Skip to main content

truncate_utf16_units

Function truncate_utf16_units 

Source
fn truncate_utf16_units(s: &str, max_units: usize) -> String
Expand description

Truncate s to at most max_units UTF-16 code units, on a UTF-8 char boundary. Mirrors JS .slice(0, n) semantics (JS strings are indexed in UTF-16 code units, so a Rust byte-length cap diverges from the TS mirror for any non-ASCII text — reagent P2, PR #2322).