Lexer

Struct Lexer 

Source
pub struct Lexer<'a> { /* private fields */ }
Expand description

Lexer has functionality to jump around and traverse the PDF lexemes of a string in any direction.

Implementations§

Source§

impl<'a> Lexer<'a>

Source

pub fn new(buf: &'a [u8]) -> Lexer<'a>

Source

pub fn with_offset(buf: &'a [u8], file_offset: usize) -> Lexer<'a>

Source

pub fn next(&mut self) -> Result<Substr<'a>>

Returns next lexeme. Lexer moves to the next byte after the lexeme. (needs to be tested)

Source

pub fn next_stream(&mut self) -> Result<()>

consume the whitespace sequence following the stream start

Source

pub fn back(&mut self) -> Result<Substr<'a>>

Gives previous lexeme. Lexer moves to the first byte of this lexeme. (needs to be tested)

Source

pub fn peek(&self) -> Result<Substr<'a>>

Look at the next lexeme. Will return empty substr if the next character is EOF.

Source

pub fn next_expect(&mut self, expected: &'static str) -> Result<()>

Returns Ok if the next lexeme matches expected - else Err.

Source

pub fn next_as<T>(&mut self) -> Result<T>
where T: FromStr, T::Err: Error + Send + Sync + 'static,

Source

pub fn get_pos(&self) -> usize

Source

pub fn new_substr(&self, range: Range<usize>) -> Substr<'a>

Source

pub fn set_pos(&mut self, wanted_pos: usize) -> Substr<'a>

Just a helper function for set_pos, set_pos_from_end and offset_pos.

Source

pub fn set_pos_from_end(&mut self, new_pos: usize) -> Substr<'a>

Returns the substr between the old and new positions

Source

pub fn offset_pos(&mut self, offset: usize) -> Substr<'a>

Returns the substr between the old and new positions

Source

pub fn seek_newline(&mut self) -> Substr<'_>

Moves pos to start of next line. Returns the skipped-over substring.

Source

pub fn seek_substr(&mut self, substr: impl AsRef<[u8]>) -> Option<Substr<'a>>

Moves pos to after the found substr. Returns Substr with traversed text if substr is found.

Source

pub fn seek_substr_back(&mut self, substr: &[u8]) -> Result<Substr<'a>>

Searches for string backward. Moves to after the found substr, returns the traversed Substr if found.

Source

pub fn read_n(&mut self, n: usize) -> Substr<'a>

Read and return slice of at most n bytes.

Source

pub fn get_remaining_slice(&self) -> &'a [u8]

Returns slice from current position to end.

Source

pub fn ctx(&self) -> Cow<'_, str>

for debugging

Trait Implementations§

Source§

impl<'a> Clone for Lexer<'a>

Source§

fn clone(&self) -> Lexer<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Lexer<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Lexer<'a>

§

impl<'a> RefUnwindSafe for Lexer<'a>

§

impl<'a> Send for Lexer<'a>

§

impl<'a> Sync for Lexer<'a>

§

impl<'a> Unpin for Lexer<'a>

§

impl<'a> UnwindSafe for Lexer<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.