pub struct LineIndex { /* private fields */ }Expand description
Precomputed line, character, and UTF-16 offset tables for a source string.
Byte offsets passed to LineIndex::line_col and
LineIndex::char_line_col are clamped to the source length, and
LineIndex::utf16_range clamps ranges to source bounds.
LineIndex::utf16_col is deliberately fallible for line/column pairs and
returns CoordinateRangeError when the pair is outside this source.
Implementations§
Source§impl LineIndex
impl LineIndex
Sourcepub const fn source_len_bytes(&self) -> ByteOffset
pub const fn source_len_bytes(&self) -> ByteOffset
Source length in bytes, represented as the EOF byte offset.
Sourcepub fn line_col(&self, offset: TextSize) -> ByteLineCol
pub fn line_col(&self, offset: TextSize) -> ByteLineCol
Maps a byte offset to a 1-based line and byte column, clamping past EOF.
Sourcepub fn char_line_col(&self, offset: TextSize) -> CharLineCol
pub fn char_line_col(&self, offset: TextSize) -> CharLineCol
Maps a byte offset to a 1-based line and Unicode scalar column.
Non-UTF-8-boundary offsets snap to the previous character boundary.
Sourcepub fn utf16_col(
&self,
line: LineNumber,
byte_col: ByteColumn,
) -> Result<Utf16Offset, CoordinateRangeError>
pub fn utf16_col( &self, line: LineNumber, byte_col: ByteColumn, ) -> Result<Utf16Offset, CoordinateRangeError>
Returns the UTF-16 code-unit offset from the start of line to byte_col.
Both coordinates must be within this source. Zero cannot be represented
by LineNumber or ByteColumn, and this method returns a typed
error instead of clamping lines or columns past the source.
§Errors
Returns CoordinateRangeError when line is past the source line
count or byte_col is past the end column for that line.
Sourcepub fn utf16_range(&self, range: TextRange) -> Utf16Range
pub fn utf16_range(&self, range: TextRange) -> Utf16Range
Maps a byte range to UTF-16 start/end offsets, clamping to source bounds.