Function line_span::find_line_range[][src]

pub fn find_line_range(text: &str, index: usize) -> Range<usize>
Expand description

Find the start and end (byte index) of the line, which index is within.

Note the end is the last character, excluding \n and \r\n.

See also

Panics

Panics if index is out of bounds.

Example

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

let range = line_span::find_line_range(text, i);
assert_eq!(range, 4..7);

let line = &text[range];
assert_eq!(line, "bar");