[][src]Function line_span::find_prev_line_start

pub fn find_prev_line_start(text: &str, index: usize) -> Option<usize>

Find the start (byte index) of the previous line, the line before the one which index is within.

Returns None if there is no previous line.

See also

Panics

Panics if index is out of bounds.

Example

let text = "foo\nbar\nbaz";
let i = 9; // 'a'

let start = line_span::find_prev_line_start(text, i).unwrap();

assert_eq!(start, 4);
assert_eq!(&text[start..], "bar\nbaz");