use super::{ErrorKind, ParseDirection, ParseError, Parser};
impl<'a> Parser<'a> {
#[inline]
pub const fn from_bytes(bytes: &'a [u8]) -> Self {
Self {
parse_direction: ParseDirection::FromStart,
start_offset: 0,
bytes,
}
}
#[inline]
pub const fn from_str(string: &'a str) -> Self {
Self {
parse_direction: ParseDirection::FromStart,
start_offset: 0,
bytes: string.as_bytes(),
}
}
#[inline(always)]
pub const fn bytes(self) -> &'a [u8] {
self.bytes
}
#[inline(always)]
pub const fn start_offset(self) -> usize {
self.start_offset as _
}
#[inline(always)]
pub const fn end_offset(self) -> usize {
self.start_offset as usize + self.bytes.len()
}
pub fn parse_direction(&self) -> ParseDirection {
self.parse_direction
}
pub const fn into_error(self, kind: ErrorKind) -> ParseError<'a> {
ParseError::new(self, kind)
}
pub const fn into_other_error(self) -> ParseError<'a> {
ParseError::new(self, ErrorKind::Other)
}
pub const fn advance_to_remainder_from_start(mut self, to: &'a [u8]) -> Self {
parsing! {self, FromStart;
self.bytes = to;
}
}
pub const fn advance_to_remainder_from_end(mut self, to: &'a [u8]) -> Self {
parsing! {self, FromEnd;
self.bytes = to;
}
}
#[inline(always)]
pub const fn len(self) -> usize {
self.bytes.len()
}
#[inline(always)]
pub const fn is_empty(self) -> bool {
self.bytes.is_empty()
}
}