Guide API
Skip to main content

prev

Function prev 

Source
pub fn prev(text: &str, index: usize) -> usize
Expand description

Byte length of the grapheme cluster ending at byte offset index in text (the cluster you would step back over from index). Returns 0 when index == 0.

Stepping cur_pos -= prev(text, cur_pos) lands the cursor on the previous cluster boundary, never inside a multi-byte codepoint or a combining sequence.

index must be a char boundary into text (it always is: every call site maintains cur_pos on grapheme boundaries). Returns 0 for index == 0.