Function ropey::str_utils::byte_to_line_idx
source ยท pub fn byte_to_line_idx(text: &str, byte_idx: usize) -> usize
Expand description
Converts from byte-index to line-index in a string slice.
Line break characters are considered to be a part of the line they end. And a string that ends with a line break is considered to have a final empty line. So this function is equivalent to counting the line breaks before the specified byte.
Any past-the-end index will return the last line index.
Runs in O(N) time.