pub fn from_byte_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.