pub struct ReadToken<'a> {
pub src: &'a str,
pub offset: usize,
}
Expand description
Stores the state of parsing.
Fields§
§src: &'a str
Source.
offset: usize
Byte offset.
Implementations§
Source§impl<'a> ReadToken<'a>
impl<'a> ReadToken<'a>
Sourcepub fn new(src: &'a str, offset: usize) -> ReadToken<'a>
pub fn new(src: &'a str, offset: usize) -> ReadToken<'a>
Creates a new ReadToken
.
The offset is in bytes.
Sourcepub fn raw_string(&self, n: usize) -> String
pub fn raw_string(&self, n: usize) -> String
Reads a raw string.
Sourcepub fn lines<F>(&self, f: F) -> Result<Range, Range>
pub fn lines<F>(&self, f: F) -> Result<Range, Range>
Read lines until closure returns None
.
Returns Ok(range)
of the successful read lines.
Returns Err(range)
when expected new line.
Sourcepub fn tag(&self, tag: &str) -> Option<Range>
pub 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.
Sourcepub fn until_any_or_whitespace(&self, any: &str) -> (Range, Option<usize>)
pub 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.
Sourcepub fn until_any(&self, any: &str) -> (Range, Option<usize>)
pub 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.
Sourcepub fn whitespace(&self) -> Range
pub fn whitespace(&self) -> Range
Reads whitespace.
Sourcepub fn number(&self, settings: &NumberSettings) -> Option<Range>
pub fn number(&self, settings: &NumberSettings) -> Option<Range>
Reads number.
Sourcepub fn parse_string(&self, n: usize) -> Result<String, Range<ParseStringError>>
pub 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.
Sourcepub fn parse_number(
&self,
settings: &NumberSettings,
n: usize,
) -> Result<f64, ParseNumberError>
pub fn parse_number( &self, settings: &NumberSettings, n: usize, ) -> Result<f64, ParseNumberError>
Parses number from n bytes.