pub struct LineIndex<'a> { /* private fields */ }Expand description
Where each line starts in a text, for turning byte offsets into lines and columns, in characters or in UTF-16 code units as editors and the language server protocol count them.
Building it is one pass over the text. A lookup is a binary search for the line and a count of at most a thousand bytes for the column.
Implementations§
Source§impl<'a> LineIndex<'a>
impl<'a> LineIndex<'a>
Sourcepub fn new(src: &'a str) -> LineIndex<'a>
pub fn new(src: &'a str) -> LineIndex<'a>
Lines ending at LF, CR or CRLF, as HTML, CSS and XML count them.
Sourcepub fn owned(src: String) -> LineIndex<'static>
pub fn owned(src: String) -> LineIndex<'static>
As LineIndex::new, keeping the text, for an index that outlives
the text it was made from, as a binding’s document does.
let lines = parsec_base::LineIndex::owned("a\nbé".to_string());
assert_eq!(lines.line_col(5).column, 3);Sourcepub fn ecmascript(src: &'a str) -> LineIndex<'a>
pub fn ecmascript(src: &'a str) -> LineIndex<'a>
Lines ending at LF, CR, CRLF, U+2028 or U+2029: ECMAScript’s LineTerminatorSequence.
pub fn line_count(&self) -> u32
Sourcepub fn line_start(&self, line: u32) -> Option<u32>
pub fn line_start(&self, line: u32) -> Option<u32>
The byte offset line line (from 1) starts at.
Sourcepub fn line(&self, offset: u32) -> u32
pub fn line(&self, offset: u32) -> u32
The line offset is on, from 1. An offset past the end is on the
last line, and a line terminator is on the line it ends.
Sourcepub fn line_col(&self, offset: u32) -> LineCol
pub fn line_col(&self, offset: u32) -> LineCol
The line and column of offset, the column in characters (Unicode
scalar values). An offset inside a character counts as after it.
Sourcepub fn line_col_utf16(&self, offset: u32) -> LineCol
pub fn line_col_utf16(&self, offset: u32) -> LineCol
The line and column of offset, the column in UTF-16 code units,
as JavaScript strings and source maps count it.
Sourcepub fn utf16_offset(&self, offset: u32) -> u32
pub fn utf16_offset(&self, offset: u32) -> u32
offset as an offset in UTF-16 code units from the start of the
text: where it is in a JavaScript string of the same text.
Sourcepub fn char_offset(&self, offset: u32) -> u32
pub fn char_offset(&self, offset: u32) -> u32
offset as an offset in characters (Unicode scalar values) from
the start of the text: where it is in a Python str of the same
text.