pub struct LineIndex<'a> { /* private fields */ }Expand description
Maps byte offsets into a source string to line/column coordinates.
Implementations§
Source§impl<'a> LineIndex<'a>
impl<'a> LineIndex<'a>
pub fn new(text: &'a str) -> Self
Sourcepub fn line_column(&self, offset: usize) -> LineColumn
pub fn line_column(&self, offset: usize) -> LineColumn
Return the one-based human-readable line and column for offset.
Columns are counted in Unicode scalar values, matching Rust chars. Out-of-range offsets
clamp to the document end; offsets in the middle of a UTF-8 sequence clamp back to the
previous character boundary.
Sourcepub fn utf16_position(&self, offset: usize) -> Utf16Position
pub fn utf16_position(&self, offset: usize) -> Utf16Position
Return the zero-based line and UTF-16 column for offset.
This is the coordinate system used by LSP. Out-of-range offsets clamp to the document end; offsets in the middle of a UTF-8 sequence clamp back to the previous character boundary.
Sourcepub fn utf8_position(&self, offset: usize) -> Utf8Position
pub fn utf8_position(&self, offset: usize) -> Utf8Position
Return the zero-based line and UTF-8 byte column for offset.
Sourcepub fn end_utf16_position(&self) -> Utf16Position
pub fn end_utf16_position(&self) -> Utf16Position
The UTF-16 position one past the last character.
Sourcepub fn end_utf8_position(&self) -> Utf8Position
pub fn end_utf8_position(&self) -> Utf8Position
The UTF-8 position one past the last byte.
Sourcepub fn offset_for_utf16_position(&self, position: Utf16Position) -> usize
pub fn offset_for_utf16_position(&self, position: Utf16Position) -> usize
The byte offset for a zero-based line and UTF-16 column.
Out-of-range lines and columns clamp to the line or document end. A UTF-16 column landing in the middle of a surrogate pair maps to the start of that character.
Sourcepub fn offset_for_utf8_position(&self, position: Utf8Position) -> usize
pub fn offset_for_utf8_position(&self, position: Utf8Position) -> usize
The byte offset for a zero-based line and UTF-8 byte column.