Skip to main content

line_column_to_byte

Function line_column_to_byte 

Source
pub fn line_column_to_byte(
    source: &str,
    line_starts: &[usize],
    pos: LineColumn,
) -> usize
Expand description

Converts a LineColumn (1-based line, 0-based character column) to a byte offset in source, using line_starts (from line_start_byte_offsets).

  • Precondition: line_starts was built from exactly source, and pos.line - 1 is in range.

  • Complexity: O(k) in pos.column.

§Examples

use cel_parser::trivia::{line_column_to_byte, line_start_byte_offsets};
let source = "é\nβ";
let lines = line_start_byte_offsets(source);
let end = proc_macro2::LineColumn { line: 2, column: 1 };
assert_eq!(line_column_to_byte(source, &lines, end), source.len());