Enum stam::ResultTextSelection
source · pub enum ResultTextSelection<'store> {
Bound(ResultItem<'store, TextSelection>),
Unbound(&'store AnnotationStore, &'store TextResource, TextSelection),
}Expand description
This structure holds a TextSelection, along with references to its TextResource and the
AnnotationStore and provides a high-level API on it.
The text selection may either be bound, in which case it corresponds to a known/existing text selection and carries a handle, or unbound, in which case it is an arbitrary textselection.
Variants§
Bound(ResultItem<'store, TextSelection>)
Unbound(&'store AnnotationStore, &'store TextResource, TextSelection)
Implementations§
source§impl<'store> ResultTextSelection<'store>
impl<'store> ResultTextSelection<'store>
sourcepub fn inner(&self) -> &TextSelection
pub fn inner(&self) -> &TextSelection
Return a reference to the inner textselection.
This works in all cases but will have a limited lifetime.
Use Self::as_ref() instead if you have bound item.
sourcepub fn as_ref(&self) -> Option<&'store TextSelection>
pub fn as_ref(&self) -> Option<&'store TextSelection>
Return a reference to the textselection in the store, with the appropriate lifetime.
Only works on bound items.
Use Self::inner() instead if you want something that always works.
sourcepub fn as_resultitem(&self) -> Option<&ResultItem<'store, TextSelection>>
pub fn as_resultitem(&self) -> Option<&ResultItem<'store, TextSelection>>
Return a reference to the textselection in the store. Only works on bound items.
sourcepub fn relative_begin(
&self,
container: &ResultTextSelection<'store>
) -> Option<usize>
pub fn relative_begin( &self, container: &ResultTextSelection<'store> ) -> Option<usize>
Returns the begin cursor of this text selection in another. Returns None if they are not embedded. This also checks whether the textselections pertain to the same resource. Returns None otherwise.
sourcepub fn relative_end(
&self,
container: &ResultTextSelection<'store>
) -> Option<usize>
pub fn relative_end( &self, container: &ResultTextSelection<'store> ) -> Option<usize>
Returns the end cursor (begin-aligned) of this text selection in another. Returns None if they are not embedded. This also checks whether the textselections pertain to the same resource. Returns None otherwise.
sourcepub fn relative_offset(
&self,
container: &ResultTextSelection<'store>,
offsetmode: OffsetMode
) -> Option<Offset>
pub fn relative_offset( &self, container: &ResultTextSelection<'store>, offsetmode: OffsetMode ) -> Option<Offset>
Returns the offset of this text selection in another. Returns None if they are not embedded. This also checks whether the textselections pertain to the same resource. Returns None otherwise.
sourcepub fn rootstore(&self) -> &'store AnnotationStore
pub fn rootstore(&self) -> &'store AnnotationStore
Return the AnnotationStore this text selection references.
sourcepub fn resource(&self) -> ResultItem<'store, TextResource>
pub fn resource(&self) -> ResultItem<'store, TextResource>
Return the resource (ResultItem<TextResource>) this text selection references.
sourcepub fn handle(&self) -> Option<TextSelectionHandle>
pub fn handle(&self) -> Option<TextSelectionHandle>
Returns the internal handle used by the TextSelection.
If the TextSelection is unbound, this will return None by definition.
sourcepub fn take(self) -> Result<TextSelection, StamError>
pub fn take(self) -> Result<TextSelection, StamError>
Takes ownership of the TextSelection, only works on unbound items, returns an error otherwise.
sourcepub fn annotations(
&self
) -> ResultIter<impl Iterator<Item = ResultItem<'store, Annotation>>> ⓘ
pub fn annotations( &self ) -> ResultIter<impl Iterator<Item = ResultItem<'store, Annotation>>> ⓘ
Iterates over all annotations that are referenced by this TextSelection, if any. For unbound selections, this returns an empty iterator by definition.
sourcepub fn annotations_len(&self) -> usize
pub fn annotations_len(&self) -> usize
Returns the number of annotations that reference this text selection For unbound selections, this is always 0.
Applies a TextSelectionOperator to find all other text selections that
are in a specific relation with the current one. Returns an iterator over the TextSelection instances.
If you are interested in the annotations associated with the found text selections, then append .annotations().
sourcepub fn positions<'a>(
&'a self,
mode: PositionMode
) -> Box<dyn Iterator<Item = &'a usize> + 'a>
pub fn positions<'a>( &'a self, mode: PositionMode ) -> Box<dyn Iterator<Item = &'a usize> + 'a>
Returns a sorted iterator over all absolute positions (begin aligned cursors) that overlap with this textselection
and are in use in the underlying resource.
By passing a PositionMode parameter you can specify whether you want only positions where a textselection begins, ends or both.
This is a low-level function. Consider using .related_text(TextSelectionOperator::overlaps()) instead.
Trait Implementations§
source§impl<'store> Clone for ResultTextSelection<'store>
impl<'store> Clone for ResultTextSelection<'store>
source§fn clone(&self) -> ResultTextSelection<'store>
fn clone(&self) -> ResultTextSelection<'store>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<'store> Debug for ResultTextSelection<'store>
impl<'store> Debug for ResultTextSelection<'store>
source§impl<'store, 'slf> FindText<'store, 'slf> for ResultTextSelection<'store>where
'store: 'slf,
impl<'store, 'slf> FindText<'store, 'slf> for ResultTextSelection<'store>where
'store: 'slf,
source§fn 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.
An offset can be specified to work on a sub-part rather than the entire text (like an existing TextSelection).
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
source§fn 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 FindText::find_text_regex() instead
If you want to search only a subpart of the text, extract a TextSelection first and then run [self.find_text()] on that instead.
source§fn 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.
This search is case insensitive, use FindText::find_text() to search case sensitive. This variant is slightly less performant than the exact variant.
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_nocase() on that instead.
source§fn 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 WITHIN the textselection.
This returns a TextSelection with absolute coordinates in the resource.
If the textselection is known (i.e. it has associated annotations), it will be returned as such with a handle (borrowed). 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 (ResultTextSelection) that also contains reference to the underlying store (the TextResource).
source§fn split_text<'b>(&'slf self, delimiter: &'b str) -> SplitTextIter<'store, 'b> ⓘ
fn split_text<'b>(&'slf self, delimiter: &'b str) -> SplitTextIter<'store, 'b> ⓘ
TextSelection instances that represent partitions
of the text given the specified delimiter. No text is modified. Read moresource§fn 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>>>
TextSelection instances wrapped as ResultTextSelection. Read moresource§fn trim_text(
&'slf self,
chars: &[char]
) -> Result<ResultTextSelection<'store>, StamError>
fn trim_text( &'slf self, chars: &[char] ) -> Result<ResultTextSelection<'store>, StamError>
chars from both the beginning and end of the text,
returning a smaller TextSelection (as a fat pointer ResultTextSelection). No text is modified.source§fn 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>
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.source§impl From<&ResultTextSelection<'_>> for Offset
impl From<&ResultTextSelection<'_>> for Offset
source§fn from(textselection: &ResultTextSelection<'_>) -> Offset
fn from(textselection: &ResultTextSelection<'_>) -> Offset
source§impl<'store> From<ResultItem<'store, TextSelection>> for ResultTextSelection<'store>
impl<'store> From<ResultItem<'store, TextSelection>> for ResultTextSelection<'store>
source§fn from(textselection: ResultItem<'store, TextSelection>) -> Self
fn from(textselection: ResultItem<'store, TextSelection>) -> Self
source§impl<'store> From<ResultTextSelection<'store>> for TextSelectionSet
impl<'store> From<ResultTextSelection<'store>> for TextSelectionSet
source§fn from(textselection: ResultTextSelection<'store>) -> Self
fn from(textselection: ResultTextSelection<'store>) -> Self
source§impl<'store> FromIterator<ResultTextSelection<'store>> for TextSelectionSet
impl<'store> FromIterator<ResultTextSelection<'store>> for TextSelectionSet
source§fn from_iter<T: IntoIterator<Item = ResultTextSelection<'store>>>(
iter: T
) -> Self
fn from_iter<T: IntoIterator<Item = ResultTextSelection<'store>>>( iter: T ) -> Self
source§impl<'store> PartialEq for ResultTextSelection<'store>
impl<'store> PartialEq for ResultTextSelection<'store>
source§impl<'store> PartialOrd for ResultTextSelection<'store>
impl<'store> PartialOrd for ResultTextSelection<'store>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<'store, 'slf> Text<'store, 'slf> for ResultTextSelection<'store>where
'store: 'slf,
impl<'store, 'slf> Text<'store, 'slf> for ResultTextSelection<'store>where
'store: 'slf,
source§fn 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
source§fn 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 The returned offset is relative to the TextSelection
source§fn utf8byte(&self, abscursor: usize) -> Result<usize, StamError>
fn utf8byte(&self, abscursor: usize) -> Result<usize, StamError>
This converts a unicode point to utf-8 byte, all in relative offsets to this textselection
source§fn utf8byte_to_charpos(&self, bytecursor: usize) -> Result<usize, StamError>
fn utf8byte_to_charpos(&self, bytecursor: usize) -> Result<usize, StamError>
This converts utf-8 byte to charpos, all in relative offsets to this textselection
source§fn textlen(&self) -> usize
fn textlen(&self) -> usize
Self::text().len() instead.