pub struct SourceText { /* private fields */ }Expand description
Immutable source text with checked UTF-8 byte and UTF-16 coordinate mapping.
The map records only boundaries immediately after non-ASCII code points. Between checkpoints, byte and UTF-16 offsets advance together through ASCII, so binary search plus one subtraction converts either direction without a per-code-point map.
Implementations§
Source§impl SourceText
impl SourceText
Sourcepub fn new(text: impl Into<Arc<str>>) -> Self
pub fn new(text: impl Into<Arc<str>>) -> Self
Stores source text and precomputes its immutable position indexes.
Sourcepub fn from_arc(text: Arc<str>) -> Self
pub fn from_arc(text: Arc<str>) -> Self
Stores an existing shared source allocation without copying its text.
Sourcepub fn byte_to_utf16(
&self,
byte_offset: usize,
) -> Result<Utf16Pos, SourcePositionError>
pub fn byte_to_utf16( &self, byte_offset: usize, ) -> Result<Utf16Pos, SourcePositionError>
Converts a UTF-8 byte boundary to a UTF-16 boundary.
Sourcepub fn utf16_to_byte(
&self,
position: Utf16Pos,
) -> Result<usize, SourcePositionError>
pub fn utf16_to_byte( &self, position: Utf16Pos, ) -> Result<usize, SourcePositionError>
Converts a UTF-16 boundary to a UTF-8 byte boundary.
Sourcepub fn range(
&self,
start: Utf16Pos,
end: Utf16Pos,
) -> Result<TextRange, SourcePositionError>
pub fn range( &self, start: Utf16Pos, end: Utf16Pos, ) -> Result<TextRange, SourcePositionError>
Returns a source-relative, ordered range after validating both endpoints.
Sourcepub fn line_column(
&self,
position: Utf16Pos,
) -> Result<(usize, usize), SourcePositionError>
pub fn line_column( &self, position: Utf16Pos, ) -> Result<(usize, usize), SourcePositionError>
Returns the zero-based line and UTF-16 column of a valid source boundary.
\r\n contributes one line break, with the next line beginning after the
\n. A bare \r, a bare \n, \u{2028} (LINE SEPARATOR), and \u{2029}
(PARAGRAPH SEPARATOR) each also begin a new line.
Trait Implementations§
Source§impl Clone for SourceText
impl Clone for SourceText
Source§fn clone(&self) -> SourceText
fn clone(&self) -> SourceText
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more