Skip to main content

Module text_boundary

Module text_boundary 

Source
Expand description

UTF-8 boundary-safe slicing helpers.

sqz slices user-controlled text (command output, session content, function signatures) at computed byte offsets in many places. Direct &s[..n] panics when n lands inside a multi-byte character — with the shell hook in the pipeline, that panic swallows the user’s entire command output (issue #34, Привет мир + a password: marker).

Every truncation of arbitrary text must go through these helpers. Slicing is only safe to do directly when the surrounding code has already proven the offset is a boundary (an ASCII-only match, a value returned by find(), a hex hash).

Functions§

floor_char_boundary
Largest byte index <= max_bytes that is a char boundary of s.
split_at_boundary_safe
Boundary-safe version of s.split_at(mid). mid is rounded DOWN to the nearest char boundary so the left side never exceeds mid bytes.
truncate_str
Boundary-safe version of &s[..max_bytes]: truncates to the largest char boundary at or below max_bytes. Never panics.