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>
impl<'a> Lexer<'a>
pub fn new(buf: &'a [u8]) -> Lexer<'a>
pub fn with_offset(buf: &'a [u8], file_offset: usize) -> Lexer<'a>
sourcepub fn next(&mut self) -> Result<Substr<'a>>
pub fn next(&mut self) -> Result<Substr<'a>>
Returns next lexeme. Lexer moves to the next byte after the lexeme. (needs to be tested)
sourcepub fn next_stream(&mut self) -> Result<()>
pub fn next_stream(&mut self) -> Result<()>
consume the whitespace sequence following the stream start
sourcepub fn back(&mut self) -> Result<Substr<'a>>
pub fn back(&mut self) -> Result<Substr<'a>>
Gives previous lexeme. Lexer moves to the first byte of this lexeme. (needs to be tested)
sourcepub fn peek(&self) -> Result<Substr<'a>>
pub fn peek(&self) -> Result<Substr<'a>>
Look at the next lexeme. Will return empty substr if the next character is EOF.
sourcepub fn next_expect(&mut self, expected: &'static str) -> Result<()>
pub fn next_expect(&mut self, expected: &'static str) -> Result<()>
Returns Ok
if the next lexeme matches expected
- else Err
.
pub fn next_as<T>(&mut self) -> Result<T>where T: FromStr, T::Err: Error + Send + Sync + 'static,
pub fn get_pos(&self) -> usize
pub fn new_substr(&self, range: Range<usize>) -> Substr<'a>
sourcepub fn set_pos(&mut self, wanted_pos: usize) -> Substr<'a>
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.
sourcepub fn set_pos_from_end(&mut self, new_pos: usize) -> Substr<'a>
pub fn set_pos_from_end(&mut self, new_pos: usize) -> Substr<'a>
Returns the substr between the old and new positions
sourcepub fn offset_pos(&mut self, offset: usize) -> Substr<'a>
pub fn offset_pos(&mut self, offset: usize) -> Substr<'a>
Returns the substr between the old and new positions
sourcepub fn seek_newline(&mut self) -> Substr<'_>
pub fn seek_newline(&mut self) -> Substr<'_>
Moves pos to start of next line. Returns the skipped-over substring.
sourcepub fn seek_substr(&mut self, substr: impl AsRef<[u8]>) -> Option<Substr<'a>>
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.
sourcepub fn seek_substr_back(&mut self, substr: &[u8]) -> Result<Substr<'a>>
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.
sourcepub fn get_remaining_slice(&self) -> &'a [u8] ⓘ
pub fn get_remaining_slice(&self) -> &'a [u8] ⓘ
Returns slice from current position to end.