byte_offset_to_line_col

Function byte_offset_to_line_col 

Source
pub fn byte_offset_to_line_col(source: &str, offset: usize) -> (usize, usize)
Expand description

Convert a byte offset to 1-based line and column numbers.

Returns (line, column) where both are 1-indexed. The column is the number of bytes from the start of the line, plus 1. If offset exceeds source.len(), it is clamped to source.len().

Performance note: This function is O(n) in the source length. For repeated lookups on the same source, use LineIndex for O(log n) lookups.