Skip to main content

floor_char_boundary

Function floor_char_boundary 

Source
pub fn floor_char_boundary(line: &str, column: usize) -> usize
Expand description

column clamped to line’s length and rounded down to a character boundary, so a byte column that is off - a malformed painting, a stale range, an offset derived from a hash - can slice line without panicking inside a multi-byte character.

The one home for this clamp. Every renderer that slices a row by column needs it, and the byte-versus-character defect it prevents is easy to reintroduce independently in each of them (see SourceColumn).