pub struct Strs(/* private fields */);Expand description
The str equivalent for Duat.
Due to Duat’s use of a gap buffer to represent the Text,
this struct doesn’t represent just one slice like a &str does.
Instead, it represents two slices (either being possibly empty).
This is done by making use of a custom dynamically sized type, allowing for near identical utilization.
Implementations§
Source§impl Strs
impl Strs
Sourcepub fn start_point(&self) -> Point
pub fn start_point(&self) -> Point
The Point at the end of the Strs.
This is the equivalent of strs.range().start.
Sourcepub fn end_point(&self) -> Point
pub fn end_point(&self) -> Point
The Point at the end of the Strs.
This is the equivalent of strs.range().end.
Sourcepub fn point_at_byte(&self, byte: usize) -> Point
pub fn point_at_byte(&self, byte: usize) -> Point
The Point corresponding to the byte position, 0 indexed.
If the byte position would fall in between two characters
(because the first one comprises more than one byte), the
first character is chosen as the Point where the byte is
located.
§Panics
Will panic if b is greater than the length of the text.
Sourcepub fn point_at_char(&self, char: usize) -> Point
pub fn point_at_char(&self, char: usize) -> Point
Sourcepub fn point_at_coords(&self, line: usize, column: usize) -> Point
pub fn point_at_coords(&self, line: usize, column: usize) -> Point
Sourcepub fn full(&self) -> &Strs
pub fn full(&self) -> &Strs
Returns an Strs for the whole Text that this one belongs
to.
You should use this function if you want to create an api that
requires the whole Strs to be used as an argument. You can
accept any Strs, then just transform it to the full one
using this function.
If this Strs is from Strs::empty, then this will
return itself.
Sourcepub fn last_point(&self) -> Point
pub fn last_point(&self) -> Point
Sourcepub fn get(&self, range: impl TextRange) -> Option<&Strs>
pub fn get(&self, range: impl TextRange) -> Option<&Strs>
Tries to get a subslice of the Strs
It will return None if the range does not start or end in
valid utf8 boundaries. If you expect the value to alway be
Some, consider using the index operator ([]) instead.
This method is conceptually similar to &str::get, but the
reference is to an Strs struct. This struct points to a
subslice of the Strss, which is actually two slices,
given the internal gap buffer representation.
This type is supposed to act nearly identically with the
str type, only differing in the fact that its maximum
lenght is u32::MAX, not usize::MAX.
Sourcepub fn empty() -> &'static Self
pub fn empty() -> &'static Self
An empty Strs, useful in some circumstances.
This is the equivalent of a literal "".
Sourcepub fn slices(&self, range: impl TextRange) -> [&[u8]; 2]
pub fn slices(&self, range: impl TextRange) -> [&[u8]; 2]
Returns a struct of two &[u8] representing a [TextRange]
from the slice.
Sourcepub fn lines(&self) -> Lines<'_> ⓘ
pub fn lines(&self) -> Lines<'_> ⓘ
Returns an iterator over the lines in a given range
The lines are inclusive, that is, it will iterate over the whole line, not just the parts within the range.
Sourcepub fn bytes(&self) -> impl DoubleEndedIterator<Item = u8>
pub fn bytes(&self) -> impl DoubleEndedIterator<Item = u8>
Sourcepub fn chars(&self) -> impl DoubleEndedIterator<Item = char>
pub fn chars(&self) -> impl DoubleEndedIterator<Item = char>
Sourcepub fn char_indices(&self) -> impl DoubleEndedIterator<Item = (usize, char)>
pub fn char_indices(&self) -> impl DoubleEndedIterator<Item = (usize, char)>
Sourcepub fn byte_range(&self) -> Range<usize>
pub fn byte_range(&self) -> Range<usize>
A Range<usize> of the bytes on this Strs.
Sourcepub fn range(&self) -> Range<Point>
pub fn range(&self) -> Range<Point>
A Range<Point> of the bytes on this Strs.
If you just care about the byte indices (most likely), check
out Strs::byte_range isntead.
Sourcepub fn indent(&self, opts: PrintOpts) -> usize
pub fn indent(&self, opts: PrintOpts) -> usize
Gets the indentation level of this Strs
This assumes that it is a line in the Strs, ending with
\n or \r\n.
This is the total “amount of spaces”, that is, how many ' '
character equivalents are here. This depends on your
PrintOpts because of the tabstop field.
Sourcepub fn is_empty_line(&self) -> bool
pub fn is_empty_line(&self) -> bool
Wether this is an empty line or not
An empty line is either \n or \r\n. If you want to check
wether a line is just whitespace, you can do this:
use duat::prelude::*;
fn is_whitespace(line: &Strs) -> bool {
line.chars().all(|char| char.is_whitespace())
}Trait Implementations§
Source§impl<'b> RegexHaystack<'b> for Strs
impl<'b> RegexHaystack<'b> for Strs
Source§fn try_search<R: RegexPattern>(
&'b self,
pat: R,
) -> Result<Matches<'b, R>, Box<Error>>
fn try_search<R: RegexPattern>( &'b self, pat: R, ) -> Result<Matches<'b, R>, Box<Error>>
Source§fn contains_pat(&'h self, pat: impl RegexPattern) -> Result<bool, Box<Error>>
fn contains_pat(&'h self, pat: impl RegexPattern) -> Result<bool, Box<Error>>
RegexPattern Read moreSource§fn matches_pat(&'h self, pat: impl RegexPattern) -> Result<bool, Box<Error>>
fn matches_pat(&'h self, pat: impl RegexPattern) -> Result<bool, Box<Error>>
RegexPattern exactly Read more