Skip to main content

LineIndex

Struct LineIndex 

Source
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>

Source

pub fn new(src: &'a str) -> LineIndex<'a>

Lines ending at LF, CR or CRLF, as HTML, CSS and XML count them.

Source

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);
Source

pub fn ecmascript(src: &'a str) -> LineIndex<'a>

Lines ending at LF, CR, CRLF, U+2028 or U+2029: ECMAScript’s LineTerminatorSequence.

Source

pub fn line_count(&self) -> u32

Source

pub fn line_start(&self, line: u32) -> Option<u32>

The byte offset line line (from 1) starts at.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<'a> Clone for LineIndex<'a>

Source§

fn clone(&self) -> LineIndex<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for LineIndex<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Forget for LineIndex<'a>

§

impl<'a> Freeze for LineIndex<'a>

§

impl<'a> Move for LineIndex<'a>

§

impl<'a> RefUnwindSafe for LineIndex<'a>

§

impl<'a> Send for LineIndex<'a>

§

impl<'a> Sync for LineIndex<'a>

§

impl<'a> Unpin for LineIndex<'a>

§

impl<'a> UnsafeUnpin for LineIndex<'a>

§

impl<'a> UnwindSafe for LineIndex<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.