Struct pdf::parser::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 copy 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> 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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.