pub struct Location<'a> { /* private fields */ }Expand description
A source indexed as vfile-location reads it: offsets in UTF-16 code units, turned into lines, columns and the byte points of core’s positions, each in constant or log time.
Implementations§
Source§impl<'a> Location<'a>
impl<'a> Location<'a>
pub fn new(source: &'a str) -> Self
pub fn source(&self) -> &'a str
pub fn is_empty(&self) -> bool
Sourcepub fn to_unit(&self, byte: usize) -> usize
pub fn to_unit(&self, byte: usize) -> usize
The UTF-16 offset of a byte offset, inside a character counting as its start.
Sourcepub fn to_byte(&self, unit: usize) -> Option<usize>
pub fn to_byte(&self, unit: usize) -> Option<usize>
The byte offset of a UTF-16 offset, unless it is past the end or inside a pair.
Sourcepub fn to_unist_point(&self, point: Point) -> UnistPoint
pub fn to_unist_point(&self, point: Point) -> UnistPoint
The unist point of a byte point, as Lines gives it, with its UTF-16 offset.
Sourcepub fn to_point(&self, unit: usize) -> Option<UnistPoint>
pub fn to_point(&self, unit: usize) -> Option<UnistPoint>
vfile-location’s toPoint: the point at a UTF-16 offset, unless past the end.
Sourcepub fn to_offset(&self, line: usize, column: usize) -> Option<usize>
pub fn to_offset(&self, line: usize, column: usize) -> Option<usize>
vfile-location’s toOffset: the UTF-16 offset of a line and column, unless the
column is past its line.
Sourcepub fn to_position<'b>(
&self,
start: usize,
end: usize,
alloc: &'b Allocator,
) -> Option<Position<'b>>
pub fn to_position<'b>( &self, start: usize, end: usize, alloc: &'b Allocator, ) -> Option<Position<'b>>
The position of a span of UTF-16 offsets: byte points when both ends start a character, unist points otherwise, none when either is past the end.
Sourcepub fn place_nlcst<'b>(
&self,
nodes: &mut [Node<'b>],
start: Option<usize>,
alloc: &'b Allocator,
) -> Option<usize>
pub fn place_nlcst<'b>( &self, nodes: &mut [Node<'b>], start: Option<usize>, alloc: &'b Allocator, ) -> Option<usize>
Place nlcst nodes one after another from a UTF-16 offset, as mdast-util-to-nlcst’s
and hast-util-to-nlcst’s patch do: each spans its text’s length, and a node
without a start or past the end has no position. The offset after them.