Skip to main content

byte_offset_to_line_col

Function byte_offset_to_line_col 

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

バイトオフセットを 1-based の (line, col) に変換する。

pest の span はバイト単位かつ char 境界に揃っているため src のスライスは安全。 LSP など、AST ノードの Span(バイトオフセット)から行・列を求める用途でも再利用する。