compute_line_column
def compute_line_column(source: Span[UInt8], position: Int) -> Tuple[Int, Int] Line and column for a byte offset, both 1-indexed.
The column counts bytes, not characters: a column past a multi-byte character will not line up with what an editor shows. Counting code points would need a second decode of the line on a path that only runs when something has already gone wrong, and the surrounding context in the message is what a reader actually uses to find the spot.
- Args
source: The document being parsed.position: Byte offset, 0-indexed.
def compute_line_column(source: String, position: Int) -> Tuple[Int, Int] Line and column for a byte offset, both 1-indexed.
- Args
source: The document being parsed.position: Byte offset, 0-indexed.