use super::{ErrorKind, ParseDirection, ParseError, Parser};
use crate::string;
impl<'a> Parser<'a> {
#[inline]
pub const fn new(string: &'a str) -> Self {
Self {
parse_direction: ParseDirection::FromStart,
start_offset: 0,
yielded_last_split: false,
str: string,
}
}
#[inline]
pub const fn with_start_offset(string: &'a str, start_offset: usize) -> Self {
Self {
parse_direction: ParseDirection::FromStart,
start_offset: start_offset as u32,
yielded_last_split: false,
str: string,
}
}
pub const fn skip(mut self, mut byte_count: usize) -> Self {
let bytes = self.str.as_bytes();
if byte_count > bytes.len() {
byte_count = bytes.len()
} else {
use konst_kernel::string::__is_char_boundary_bytes;
while !__is_char_boundary_bytes(bytes, byte_count) {
byte_count += 1;
}
};
self.parse_direction = ParseDirection::FromStart;
self.start_offset += byte_count as u32;
self.str = string::str_from(self.str, byte_count);
self
}
pub const fn skip_back(mut self, byte_count: usize) -> Self {
use konst_kernel::string::__is_char_boundary_bytes;
let bytes = self.str.as_bytes();
let mut pos = self.str.len().saturating_sub(byte_count);
while !__is_char_boundary_bytes(bytes, pos) {
pos -= 1;
}
self.parse_direction = ParseDirection::FromEnd;
self.str = string::str_up_to(self.str, pos);
self
}
#[inline(always)]
pub const fn remainder(self) -> &'a str {
self.str
}
#[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.str.len()
}
pub const 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, string: &'static &'static str) -> ParseError<'a> {
ParseError::other_error(self, string)
}
#[inline(always)]
pub const fn len(self) -> usize {
self.str.len()
}
#[inline(always)]
pub const fn is_empty(self) -> bool {
self.str.is_empty()
}
}