pub struct ParseableStr<'t, B: Backing> {
pub position: usize,
pub backing: &'t B,
pub s: &'t str,
}Fields§
§position: usize§backing: &'t B§s: &'t strImplementations§
Source§impl<'t, B: Backing> ParseableStr<'t, B>
impl<'t, B: Backing> ParseableStr<'t, B>
pub fn new(backing: &'t B) -> Self
Sourcepub fn position_difference(&self, to: &Self) -> usize
pub fn position_difference(&self, to: &Self) -> usize
Panics if to is before self.
Sourcepub fn eos(&self) -> ParseableStr<'t, B>
pub fn eos(&self) -> ParseableStr<'t, B>
Return the end of this string, with the correct position.
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
pub fn first(&self) -> Option<char>
Sourcepub fn starts_with(&self, s: &str) -> bool
pub fn starts_with(&self, s: &str) -> bool
You usually want drop_str instead.
Source§impl<'t, B: Backing> ParseableStr<'t, B>
impl<'t, B: Backing> ParseableStr<'t, B>
Sourcepub fn parse<T: FromStr>(&self) -> Result<T, Box<FromStrError>>
pub fn parse<T: FromStr>(&self) -> Result<T, Box<FromStrError>>
Parse the whole string via FromStr, returning error information.
Sourcepub fn skip_bytes(&self, num_bytes: usize) -> ParseableStr<'t, B>
pub fn skip_bytes(&self, num_bytes: usize) -> ParseableStr<'t, B>
Skip the given number of bytes from the beginning. Panics if num_bytes goes beyond the end of self, and will lead to later panics if the result is not pointing at a character boundary.
Sourcepub fn split_at(&self, mid: usize) -> (ParseableStr<'t, B>, ParseableStr<'t, B>)
pub fn split_at(&self, mid: usize) -> (ParseableStr<'t, B>, ParseableStr<'t, B>)
Split at the given number of bytes from the beginning. Panics if mid > len, or not pointing at a character boundary.
Sourcepub fn trim(&self) -> ParseableStr<'t, B>
pub fn trim(&self) -> ParseableStr<'t, B>
Trim whitespace from start end end.
Sourcepub fn trim_start(&self) -> ParseableStr<'t, B>
pub fn trim_start(&self) -> ParseableStr<'t, B>
Trim whitespace from the end.
Sourcepub fn trim_end(&self) -> ParseableStr<'t, B>
pub fn trim_end(&self) -> ParseableStr<'t, B>
Trim whitespace from the end.
Sourcepub fn find_str(&self, needle: &str) -> Option<ParseableStr<'t, B>>
pub fn find_str(&self, needle: &str) -> Option<ParseableStr<'t, B>>
Find the first occurrence of needle in self, return
the needle and what follows.
Sourcepub fn find_str_rest(
&self,
needle: &str,
) -> Option<(ParseableStr<'t, B>, ParseableStr<'t, B>)>
pub fn find_str_rest( &self, needle: &str, ) -> Option<(ParseableStr<'t, B>, ParseableStr<'t, B>)>
Find the first occurrence of needle in self, return the
needle itself (with the position information of where it was
found) and the rest after it.
Sourcepub fn after_str(&self, needle: &str) -> Option<ParseableStr<'t, B>>
pub fn after_str(&self, needle: &str) -> Option<ParseableStr<'t, B>>
Find the first occurrence of needle in self, return
the rest after it.
Sourcepub fn drop_str(&self, beginning: &str) -> Option<ParseableStr<'t, B>>
pub fn drop_str(&self, beginning: &str) -> Option<ParseableStr<'t, B>>
Expect beginning at the start of self, if so return the
remainder after it.
Sourcepub fn expect_str(
&self,
beginning: &'t str,
) -> Result<ParseableStr<'t, B>, Box<ExpectedString<'t, B>>>
pub fn expect_str( &self, beginning: &'t str, ) -> Result<ParseableStr<'t, B>, Box<ExpectedString<'t, B>>>
Same as drop_str but returns an error mentioning
beginning if it doesn’t match
pub fn expect_str_or_eos( &self, beginning: &'t str, ) -> Result<ParseableStr<'t, B>, Box<ExpectedString<'t, B>>>
pub fn expect_separator( &self, separator: &Separator, ) -> Result<ParseableStr<'t, B>, Box<ExpectedString<'t, B>>>
Sourcepub fn take_until_str(&self, needle: &str) -> Option<ParseableStr<'t, B>>
pub fn take_until_str(&self, needle: &str) -> Option<ParseableStr<'t, B>>
Find the first occurrence of needle in self, return the part
left of it.
Sourcepub fn split_at_str(
&self,
needle: &str,
) -> Option<(ParseableStr<'t, B>, ParseableStr<'t, B>)>
pub fn split_at_str( &self, needle: &str, ) -> Option<(ParseableStr<'t, B>, ParseableStr<'t, B>)>
Split at the first occurrence of needle, returning the parts
before and after it.
Sourcepub fn take_while(
&self,
pred: impl FnMut(char) -> bool,
) -> (ParseableStr<'t, B>, ParseableStr<'t, B>)
pub fn take_while( &self, pred: impl FnMut(char) -> bool, ) -> (ParseableStr<'t, B>, ParseableStr<'t, B>)
Take every character for which pred returns true, return the
string making up those characters and the remainder.
Sourcepub fn expect1_matching(
&self,
pred: impl FnOnce(char) -> bool,
desc: &'t str,
) -> Result<ParseableStr<'t, B>, Box<Expected<'t, B>>>
pub fn expect1_matching( &self, pred: impl FnOnce(char) -> bool, desc: &'t str, ) -> Result<ParseableStr<'t, B>, Box<Expected<'t, B>>>
Expect 1 character for which pred must return true, return
the string making up the remainder.
pub fn take_identifier( &self, ) -> Result<(ParseableStr<'t, B>, ParseableStr<'t, B>), Box<Expected<'t, B>>>
pub fn drop_while(&self, pred: impl FnMut(char) -> bool) -> ParseableStr<'t, B>
Sourcepub fn take_n_while(
&self,
n: usize,
pred: impl FnMut(char) -> bool,
desc: &'t str,
) -> Result<(ParseableStr<'t, B>, ParseableStr<'t, B>), Box<Expected<'t, B>>>
pub fn take_n_while( &self, n: usize, pred: impl FnMut(char) -> bool, desc: &'t str, ) -> Result<(ParseableStr<'t, B>, ParseableStr<'t, B>), Box<Expected<'t, B>>>
Take n characters matching pred. Does not check whether
there are more than n characters matching pred, just
returns what was found so far.
Sourcepub fn take_nrange_while(
&self,
n_min: usize,
n_max: usize,
pred: impl FnMut(char) -> bool,
desc: &'t str,
) -> Result<(ParseableStr<'t, B>, ParseableStr<'t, B>), Box<Expected<'t, B>>>
pub fn take_nrange_while( &self, n_min: usize, n_max: usize, pred: impl FnMut(char) -> bool, desc: &'t str, ) -> Result<(ParseableStr<'t, B>, ParseableStr<'t, B>), Box<Expected<'t, B>>>
Take n_min to n_max (inclusive) characters matching
pred. Does not check whether there are more than n_max
characters matching pred, just returns what was found so
far.
pub fn drop_whitespace(&self) -> ParseableStr<'t, B>
Sourcepub fn split_str<'r, 'n>(
&'r self,
separator: &'n str,
omit_empty_last_item: bool,
) -> Box<dyn Iterator<Item = ParseableStr<'t, B>> + 'n>where
't: 'n,
'r: 'n,
pub fn split_str<'r, 'n>(
&'r self,
separator: &'n str,
omit_empty_last_item: bool,
) -> Box<dyn Iterator<Item = ParseableStr<'t, B>> + 'n>where
't: 'n,
'r: 'n,
Split on a fixed string, separator; the separator string
is not included in the returned parts. If
omit_empty_last_item is true, if there’s an empty string
after the last separator, it is not reported as an item.