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§
sourcefn textlen(&self) -> usize
fn textlen(&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 subslice_utf8_offset(&self, subslice: &str) -> Option<usize>
fn subslice_utf8_offset(&self, subslice: &str) -> Option<usize>
Finds the utf-8 byte position where the specified text subslice begins
sourcefn utf8byte(&self, abscursor: usize) -> Result<usize, StamError>
fn utf8byte(&self, abscursor: usize) -> Result<usize, StamError>
Converts a unicode character position to a UTF-8 byte position
sourcefn utf8byte_to_charpos(&self, bytecursor: usize) -> Result<usize, StamError>
fn utf8byte_to_charpos(&self, bytecursor: usize) -> Result<usize, StamError>
Converts a UTF-8 byte position into a unicode position
fn find_text_regex<'regex>( &'slf self, expressions: &'regex [Regex], precompiledset: Option<&RegexSet>, allow_overlap: bool ) -> Result<FindRegexIter<'store, 'regex>, StamError>
sourcefn find_text<'fragment>(
&'slf self,
fragment: &'fragment str
) -> FindTextIter<'store, 'fragment>
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.
sourcefn find_text_nocase(&'slf self, fragment: &str) -> FindNoCaseTextIter<'store>
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.
sourcefn split_text<'b>(&'slf self, delimiter: &'b str) -> SplitTextIter<'store, 'b>
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.
sourcefn textselection(
&'slf self,
offset: &Offset
) -> Result<WrappedItem<'store, TextSelection>, StamError>
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.
sourcefn absolute_cursor(&self, cursor: usize) -> usize
fn absolute_cursor(&self, cursor: usize) -> usize
Resolves a begin-aligned cursor to an absolute cursor (i.e. relative to the TextResource).
Provided Methods§
sourcefn 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 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.
sourcefn trim_text(
&'slf self,
chars: &[char]
) -> Result<WrappedItem<'store, TextSelection>, StamError>
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.