Struct read_token::ReadToken
[−]
[src]
pub struct ReadToken<'a> { pub src: &'a str, pub offset: usize, }
Stores the state of parsing.
Fields
src: &'a str
Source.
offset: usize
Byte offset.
Methods
impl<'a> ReadToken<'a>
[src]
fn new(src: &'a str, offset: usize) -> ReadToken<'a>
Creates a new ReadToken
.
The offset is in bytes.
fn consume(self, n: usize) -> ReadToken<'a>
Consumes n bytes.
fn raw_string(&self, n: usize) -> String
Reads a raw string.
fn lines<F>(&self, f: F) -> Result<Range, Range> where
F: FnMut(&ReadToken) -> Option<Range>,
F: FnMut(&ReadToken) -> Option<Range>,
Read lines until closure returns None
.
Returns Ok(range)
of the successful read lines.
Returns Err(range)
when expected new line.
fn subtract(&self, rhs: &Self) -> Range
Returns the difference in offset.
fn start(&self) -> Range
Returns an empty range at current offset.
fn peek(&self, n: usize) -> Range
Peek a number of bytes ahead.
fn tag(&self, tag: &str) -> Option<Range>
Reads an expected tag, returns character range and new state. Returns old state when fail to match tag.
fn until_any_or_whitespace(&self, any: &str) -> (Range, Option<usize>)
Reads a token until any character in string or whitespace.
Returns (range, None)
if stopping at whitespace or end of text.
Returns (range, Some(x))
if stopping at a character.
fn until_any(&self, any: &str) -> (Range, Option<usize>)
Reads token until any character in string.
Returns (new_state, range, None)
if stopping at end of text.
Returns (new_state, range, Some(x))
if stopping at a character.
fn whitespace(&self) -> Range
Reads whitespace.
fn string(&self) -> Option<Range>
Reads string with character escapes.
fn number(&self, settings: &NumberSettings) -> Option<Range>
Reads number.
fn parse_string(&self, n: usize) -> Result<String, Range<ParseStringError>>
Parses string into a real string according to the JSON standard.
Assumes the string starts and ends with double-quotes.
n
is the number of bytes to read and must be at least 2,
because the string is surrounded by quotes.
fn parse_number(
&self,
settings: &NumberSettings,
n: usize
) -> Result<f64, ParseNumberError>
&self,
settings: &NumberSettings,
n: usize
) -> Result<f64, ParseNumberError>
Parses number from n bytes.
Trait Implementations
impl<'a> Copy for ReadToken<'a>
[src]
impl<'a> Clone for ReadToken<'a>
[src]
fn clone(&self) -> ReadToken<'a>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more