pub fn line_for_byte(text: &str, byte: usize) -> usizeExpand description
Counts newline bytes before a UTF-8 byte offset.
Offsets beyond the text are clamped to text.len().
§Panics
Panics when an in-bounds byte is not a UTF-8 character boundary.
§Examples
use ailloli_ui_editor::code::line_for_byte;
let text = "é\nnext";
assert_eq!(line_for_byte(text, 2), 0);
assert_eq!(line_for_byte(text, 3), 1);
assert_eq!(line_for_byte(text, usize::MAX), 1);