pub struct LineIndex<'text> { /* private fields */ }Expand description
Reusable line index for strict Weavatrix v1 UTF-16 positions.
Implementations§
Source§impl<'text> LineIndex<'text>
impl<'text> LineIndex<'text>
Sourcepub fn new(text: &'text str) -> Self
pub fn new(text: &'text str) -> Self
Builds a reusable full line index.
This compatibility constructor retains its infallible signature. Code
handling untrusted or very large text should use Self::try_new with
explicit resource ceilings instead.
§Panics
Panics if the complete line-start table cannot be represented or
allocated. Use Self::try_new to receive a bounded error instead.
Sourcepub fn try_new(
text: &'text str,
limits: LineIndexLimits,
) -> Result<Self, EditError>
pub fn try_new( text: &'text str, limits: LineIndexLimits, ) -> Result<Self, EditError>
Builds a reusable full line index within explicit resource limits.
The source is borrowed rather than copied. The complete line-start table is counted before allocation, checked against both limits, and reserved fallibly so hostile newline-heavy input returns an error instead of relying on an allocator panic.
Sourcepub fn byte_offset(&self, position: Position) -> Result<usize, EditError>
pub fn byte_offset(&self, position: Position) -> Result<usize, EditError>
Resolves a 1-based line and 0-based UTF-16 code-unit position.
The line feed is excluded from the line length. For compatibility with
weavatrix.edit-plan.v1, a preceding carriage return remains part of a
CRLF line. Positions inside an astral Unicode scalar fail closed.
Sourcepub fn byte_offset_with_encoding(
&self,
position: Position,
encoding: PositionEncoding,
) -> Result<usize, EditError>
pub fn byte_offset_with_encoding( &self, position: Position, encoding: PositionEncoding, ) -> Result<usize, EditError>
Resolves a strict position using UTF-8, UTF-16, or UTF-32 character units.
Sourcepub fn position_at(
&self,
byte_offset: usize,
encoding: PositionEncoding,
) -> Result<Position, EditError>
pub fn position_at( &self, byte_offset: usize, encoding: PositionEncoding, ) -> Result<Position, EditError>
Maps a UTF-8 byte boundary back to a strict line/character position.