Function ropey::str_utils::byte_to_char_idx

source ยท
pub fn byte_to_char_idx(text: &str, byte_idx: usize) -> usize
Expand description

Converts from byte-index to char-index in a string slice.

If the byte is in the middle of a multi-byte char, returns the index of the char that the byte belongs to.

Any past-the-end index will return the one-past-the-end char index.

Runs in O(N) time.