pub fn byte_offset_to_line_col<K, I>(
bytes: I,
offset: usize,
) -> Result<(usize, usize), ParseError>
Expand description
Returns the line and column of the character at the offset within the iterator.
Offsets are assumed to be 0 indexed, and lines and columns are 1 indexed.
§Errors
Will return an ParseError::NotFound
if the offset is past the end of the iterator.
§Example
use device_tree_source::byte_offset_to_line_col;
use device_tree_source::ParseError;
let string = "Howdy\nHow goes it\n\nI'm doing fine";
assert_eq!(byte_offset_to_line_col(string.as_bytes().iter(), 0), Ok((1, 1)));
assert_eq!(byte_offset_to_line_col(string.as_bytes().iter(), 8), Ok((2, 3)));
assert_eq!(byte_offset_to_line_col(string.as_bytes().iter(), 33), Err(ParseError::NotFound));