Trait stam::Text

source ·
pub trait Text<'store, 'slf>where
    'store: 'slf,{
Show 16 methods // Required methods fn text(&'slf self) -> &'store str; fn textlen(&self) -> usize; fn text_by_offset( &'slf self, offset: &Offset ) -> Result<&'store str, StamError>; fn subslice_utf8_offset(&self, subslice: &str) -> Option<usize>; fn utf8byte(&self, abscursor: usize) -> Result<usize, StamError>; fn utf8byte_to_charpos(&self, bytecursor: usize) -> Result<usize, StamError>; fn find_text_regex<'regex>( &'slf self, expressions: &'regex [Regex], precompiledset: Option<&RegexSet>, allow_overlap: bool ) -> Result<FindRegexIter<'store, 'regex>, StamError>; fn find_text<'fragment>( &'slf self, fragment: &'fragment str ) -> FindTextIter<'store, 'fragment>; fn find_text_nocase( &'slf self, fragment: &str ) -> FindNoCaseTextIter<'store>; fn split_text<'b>( &'slf self, delimiter: &'b str ) -> SplitTextIter<'store, 'b>; fn textselection( &'slf self, offset: &Offset ) -> Result<WrappedItem<'store, TextSelection>, StamError>; fn absolute_cursor(&self, cursor: usize) -> usize; // Provided methods fn find_text_sequence<'fragment, F>( &'slf self, fragments: &'fragment [&'fragment str], allow_skip_char: F, case_sensitive: bool ) -> Option<Vec<WrappedItem<'store, TextSelection>>> where F: Fn(char) -> bool { ... } fn trim_text( &'slf self, chars: &[char] ) -> Result<WrappedItem<'store, TextSelection>, StamError> { ... } fn beginaligned_cursor(&self, cursor: &Cursor) -> Result<usize, StamError> { ... } fn absolute_offset(&self, offset: &Offset) -> Result<Offset, StamError> { ... }
}
Expand description

This trait provides methods that operate on structures that hold or represent text content.

Required Methods§

source

fn text(&'slf self) -> &'store str

Returns a reference to the text

source

fn textlen(&self) -> usize

Returns the length of the text in unicode points For bytes, use Self.text().len() instead.

source

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

source

fn subslice_utf8_offset(&self, subslice: &str) -> Option<usize>

Finds the utf-8 byte position where the specified text subslice begins

source

fn utf8byte(&self, abscursor: usize) -> Result<usize, StamError>

Converts a unicode character position to a UTF-8 byte position

source

fn utf8byte_to_charpos(&self, bytecursor: usize) -> Result<usize, StamError>

Converts a UTF-8 byte position into a unicode position

source

fn find_text_regex<'regex>( &'slf self, expressions: &'regex [Regex], precompiledset: Option<&RegexSet>, allow_overlap: bool ) -> Result<FindRegexIter<'store, 'regex>, StamError>

source

fn find_text<'fragment>( &'slf self, fragment: &'fragment str ) -> FindTextIter<'store, 'fragment>

Searches for the specified text fragment. Returns an iterator to iterate over all matches in the text. The iterator returns TextSelection items.

For more complex and powerful searching use [Self.find_text_regex()] instead

If you want to search only a subpart of the text, extract a [’TextSelection] first with [Self.textselection()] and then run find_text()` on that instead.

source

fn find_text_nocase(&'slf self, fragment: &str) -> FindNoCaseTextIter<'store>

Searches for the specified text fragment. Returns an iterator to iterate over all matches in the text. The iterator returns TextSelection items.

For more complex and powerful searching use [Self.find_text_regex()] instead

If you want to search only a subpart of the text, extract a [’TextSelection] first with [Self.textselection()] and then run find_text()` on that instead.

source

fn split_text<'b>(&'slf self, delimiter: &'b str) -> SplitTextIter<'store, 'b>

Returns an iterator of [’TextSelection`] instances that represent partitions of the text given the specified delimiter. No text is modified.

The iterator returns wrapped TextSelection items.

source

fn textselection( &'slf self, offset: &Offset ) -> Result<WrappedItem<'store, TextSelection>, StamError>

Returns a [TextSelection'] that corresponds to the offset. If the TextSelection exists, the existing one will be returned (as a copy, but it will have a TextSelection.handle()). If it doesn't exist yet, a new one will be returned, and it won't have a handle, nor will it be added to the store automatically. The [TextSelection] is returned as in a far pointer (WrappedItem`) that also contains reference to the underlying store.

Use [Resource::has_textselection()] instead if you want to limit to existing text selections on resources.

source

fn absolute_cursor(&self, cursor: usize) -> usize

Resolves a begin-aligned cursor to an absolute cursor (i.e. relative to the TextResource).

Provided Methods§

source

fn find_text_sequence<'fragment, F>( &'slf self, fragments: &'fragment [&'fragment str], allow_skip_char: F, case_sensitive: bool ) -> Option<Vec<WrappedItem<'store, TextSelection>>>where F: Fn(char) -> bool,

Searches for the multiple text fragment in sequence. Returns a vector with (wrapped) TextSelection instances.

Matches must appear in the exact order specified, but may have other intermittent text, determined by the allow_skip_char closure. A recommended closure for natural language text is: |c| !c.is_alphabetic()

The case_sensitive parameter determines if the search is case sensitive or not, case insensitive searches have a performance penalty.

source

fn trim_text( &'slf self, chars: &[char] ) -> Result<WrappedItem<'store, TextSelection>, StamError>

Trims all occurrences of any character in chars from both the beginning and end of the text, returning a smaller TextSelection. No text is modified.

source

fn beginaligned_cursor(&self, cursor: &Cursor) -> Result<usize, StamError>

Resolves a cursor to a begin aligned cursor, resolving all relative end-aligned positions

source

fn absolute_offset(&self, offset: &Offset) -> Result<Offset, StamError>

Resolves a relative offset (relative to another TextSelection) to an absolute one (in terms of to the underlying TextResource)

Implementors§

source§

impl<'store> Text<'store, 'store> for TextResource

source§

impl<'store, 'slf> Text<'store, 'slf> for WrappedItem<'store, TextSelection>where 'store: 'slf,