pub trait Text<'store, 'slf>where
'store: 'slf,{
// Required methods
fn text(&'slf self) -> &'store str;
fn textlen(&'slf self) -> usize;
fn text_by_offset(
&'slf self,
offset: &Offset
) -> Result<&'store str, StamError>;
fn utf8byte(&'slf self, abscursor: usize) -> Result<usize, StamError>;
fn utf8byte_to_charpos(
&'slf self,
bytecursor: usize
) -> Result<usize, StamError>;
fn absolute_cursor(&'slf self, cursor: usize) -> usize;
// Provided methods
fn subslice_utf8_offset(&'slf self, subslice: &str) -> Option<usize> { ... }
fn is_empty(&'slf self) -> bool { ... }
fn absolute_offset(&'slf self, offset: &Offset) -> Result<Offset, StamError> { ... }
fn beginaligned_cursor(
&'slf self,
cursor: &Cursor
) -> Result<usize, StamError> { ... }
}Expand description
This trait provides methods that operate on structures that hold or represent text content.
They are fairly low-level methods but are exposed in the public API. The FindText
trait subsequently builds upon this one with high-level search methods.
Required Methods§
sourcefn textlen(&'slf self) -> usize
fn textlen(&'slf self) -> usize
Returns the length of the text in unicode points
For bytes, use Self::text().len() instead.
sourcefn text_by_offset(&'slf self, offset: &Offset) -> Result<&'store str, StamError>
fn text_by_offset(&'slf self, offset: &Offset) -> Result<&'store str, StamError>
Returns a string reference to a slice of text as specified by the offset
sourcefn utf8byte(&'slf self, abscursor: usize) -> Result<usize, StamError>
fn utf8byte(&'slf self, abscursor: usize) -> Result<usize, StamError>
Converts a unicode character position to a UTF-8 byte position
sourcefn utf8byte_to_charpos(
&'slf self,
bytecursor: usize
) -> Result<usize, StamError>
fn utf8byte_to_charpos( &'slf self, bytecursor: usize ) -> Result<usize, StamError>
Converts a UTF-8 byte position into a unicode position
sourcefn absolute_cursor(&'slf self, cursor: usize) -> usize
fn absolute_cursor(&'slf self, cursor: usize) -> usize
Resolves a begin-aligned cursor to an absolute cursor (i.e. relative to the TextResource).
Provided Methods§
sourcefn subslice_utf8_offset(&'slf self, subslice: &str) -> Option<usize>
fn subslice_utf8_offset(&'slf self, subslice: &str) -> Option<usize>
Finds the utf-8 byte position where the specified text subslice begins The returned offset is relative to the TextSelection
fn is_empty(&'slf self) -> bool
Implementors§
impl<'store> Text<'store, 'store> for TextResource
impl<'store, 'slf> Text<'store, 'slf> for ResultTextSelection<'store>where
'store: 'slf,
impl<'store, 'slf> Text<'store, 'slf> for ResultItem<'store, TextResource>where
'store: 'slf,
this implementation mostly defers directly to the wrapped item, documentation is found on the trait and not repeated here