Skip to main content

line_col_to_byte_offset

Function line_col_to_byte_offset 

Source
pub fn line_col_to_byte_offset(input: &str, line: usize, col: usize) -> usize
Expand description

Helper to convert a 1-indexed line and column to a 0-indexed byte offset in the input string.

§Arguments

  • input - The raw JSON string slice.
  • line - The 1-indexed line number where the error occurred.
  • col - The 1-indexed column number where the error occurred.

§Returns

The 0-indexed byte offset of the character in the input string. If line is 0, 0 is returned. If line or col exceeds the boundaries of the string, the length of the string is returned.