pub trait FindText<'store, 'slf>: Text<'store, 'slf>where
'store: 'slf,{
// Required methods
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<ResultTextSelection<'store>, StamError>;
// Provided methods
fn find_text_sequence<'fragment, F>(
&'slf self,
fragments: &'fragment [&'fragment str],
allow_skip_char: F,
case_sensitive: bool,
) -> Option<Vec<ResultTextSelection<'store>>>
where F: Fn(char) -> bool { ... }
fn trim_text(
&'slf self,
chars: &[char],
) -> Result<ResultTextSelection<'store>, StamError> { ... }
fn trim_text_with<F>(
&'slf self,
f: F,
) -> Result<ResultTextSelection<'store>, StamError>
where F: Fn(char) -> bool { ... }
}Expand description
This trait provides text-searching methods that operate on structures that hold or represent text content. It builds upon the lower-level Text trait.
Required Methods§
Sourcefn find_text_regex<'regex>(
&'slf self,
expressions: &'regex [Regex],
precompiledset: Option<&RegexSet>,
allow_overlap: bool,
) -> Result<FindRegexIter<'store, 'regex>, StamError>
fn find_text_regex<'regex>( &'slf self, expressions: &'regex [Regex], precompiledset: Option<&RegexSet>, allow_overlap: bool, ) -> Result<FindRegexIter<'store, 'regex>, StamError>
Searches the text using one or more regular expressions, returns an iterator over TextSelections along with the matching expression, this
is held by the FindRegexMatch struct.
Passing multiple regular expressions at once is more efficient than calling this function anew for each one. If capture groups are used in the regular expression, only those parts will be returned (the rest is context). If none are used, the entire expression is returned.
The allow_overlap parameter determines if the matching expressions are allowed to
overlap. It you are doing some form of tokenisation, you also likely want this set to
false. All of this only matters if you supply multiple regular expressions.
Results are returned in the exact order they are found in the text
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 encapsulated TextSelection items as ResultTextSelection.
For more complex and powerful searching use FindText::find_text_regex() instead
If you want to search only a subpart of the text, extract a TextSelection first with
FindText::textselection() and then run FindText::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 wrapped as ResultTextSelection.
For more complex and powerful searching use FindText::find_text_regex() instead
If you want to search only a subpart of the text, extract a TextSelection first with
FindText::textselection() and then run FindText::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 TextSelection items as a fat pointer ResultTextSelection).
Sourcefn textselection(
&'slf self,
offset: &Offset,
) -> Result<ResultTextSelection<'store>, StamError>
fn textselection( &'slf self, offset: &Offset, ) -> Result<ResultTextSelection<'store>, 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 fat pointer (ResultTextSelection) that also contains reference to the underlying store.
Use TextResource::known_textselection() instead if you want to limit to existing text selections on resources.
Provided Methods§
Sourcefn find_text_sequence<'fragment, F>(
&'slf self,
fragments: &'fragment [&'fragment str],
allow_skip_char: F,
case_sensitive: bool,
) -> Option<Vec<ResultTextSelection<'store>>>
fn find_text_sequence<'fragment, F>( &'slf self, fragments: &'fragment [&'fragment str], allow_skip_char: F, case_sensitive: bool, ) -> Option<Vec<ResultTextSelection<'store>>>
Searches for the multiple text fragment in sequence. Returns a vector with
TextSelection instances wrapped as ResultTextSelection.
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<ResultTextSelection<'store>, StamError>
fn trim_text( &'slf self, chars: &[char], ) -> Result<ResultTextSelection<'store>, StamError>
Trims all occurrences of any character in chars from both the beginning and end of the text,
returning a smaller TextSelection (as a fat pointer ResultTextSelection). No text is modified.
Sourcefn trim_text_with<F>(
&'slf self,
f: F,
) -> Result<ResultTextSelection<'store>, StamError>
fn trim_text_with<F>( &'slf self, f: F, ) -> Result<ResultTextSelection<'store>, StamError>
Trims all occurrences of any character chars that pass the supplied function, from both the beginning and end of the text,
returning a smaller TextSelection (as a fat pointer ResultTextSelection). No text is modified.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".