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_bytesthat is acharboundary ofs. - split_
at_ boundary_ safe - Boundary-safe version of
s.split_at(mid).midis rounded DOWN to the nearest char boundary so the left side never exceedsmidbytes. - truncate_
str - Boundary-safe version of
&s[..max_bytes]: truncates to the largest char boundary at or belowmax_bytes. Never panics.