Orcus
Protected Types | Protected Member Functions | Protected Attributes | List of all members
orcus::parser_base Class Reference
Inheritance diagram for orcus::parser_base:
orcus::css::parser_base orcus::csv::parser_base orcus::json::parser_base orcus::sax::parser_base orcus::yaml::parser_base orcus::css_parser< HandlerT > orcus::csv_parser< HandlerT > orcus::json_parser< HandlerT > orcus::sax_parser< handler_wrapper > orcus::sax_parser< HandlerT, ConfigT > orcus::yaml_parser< HandlerT >

Protected Types

using numeric_parser_type = std::function< const char *(const char *, const char *, double &)>
 

Protected Member Functions

 parser_base (const char *p, size_t n)
 
void set_numeric_parser (const numeric_parser_type &func)
 
bool has_char () const
 
bool has_next () const
 
void next (size_t inc=1)
 
void prev (size_t dec=1)
 
char cur_char () const
 
char peek_char (std::size_t offset=1) const
 
std::string_view peek_chars (std::size_t length) const
 
void skip_bom ()
 
void skip (std::string_view chars_to_skip)
 
void skip_space_and_control ()
 
bool parse_expected (std::string_view expected)
 
double parse_double ()
 
size_t remaining_size () const
 
size_t available_size () const
 
std::ptrdiff_t offset () const
 

Protected Attributes

const char *const mp_begin
 
const char * mp_char
 
const char * mp_end
 

Member Function Documentation

◆ available_size()

size_t orcus::parser_base::available_size ( ) const
inlineprotected

Determine the number of characters available from the current character to the end of the buffer. The current character is included.

Returns
number of characters available including the current character.

◆ offset()

std::ptrdiff_t orcus::parser_base::offset ( ) const
protected

Return the current offset from the beginning of the character stream.

Returns
current offset from the beginning of the character stream.

◆ parse_double()

double orcus::parser_base::parse_double ( )
protected

Try to parse the next characters as double, or return NaN in case of failure.

Returns
double value on success, or NaN on failure.

◆ parse_expected()

bool orcus::parser_base::parse_expected ( std::string_view  expected)
protected

Parse and check next characters to see if it matches specified character sequence.

Parameters
expectedsequence of characters to match against.
Returns
true if it matches specified character sequence, false otherwise.

◆ peek_char()

char orcus::parser_base::peek_char ( std::size_t  offset = 1) const
protected

Peek a character at specified offset from the current position without advancing the current position.

Note
The caller must ensure that the specified offset position is a valid position. This method does not check its validity.
Parameters
offsetoffset from the current position to peek at.
Returns
character at a specified offset position from the current position.

◆ peek_chars()

std::string_view orcus::parser_base::peek_chars ( std::size_t  length) const
protected

Peek a segment of contiguous characters of a specified length starting from the current position.

Note
The caller must ensure that the specified substring segment is entirely valid. This method does not check its validity.
Parameters
lengthlength of the segment to peek.
Returns
segment of contiguous characters.

◆ remaining_size()

size_t orcus::parser_base::remaining_size ( ) const
protected

Determine the number of characters remaining after the current character. For instance, if the current character is on the last character in the stream, this method will return 0, whereas if it's on the first character, it will return the total length - 1.

Returns
number of characters remaining after the current character.

◆ skip_bom()

void orcus::parser_base::skip_bom ( )
protected

Skip an optional byte order mark at the current position of the stream.

Currently we only check for UTF-8 BOM.

◆ skip_space_and_control()

void orcus::parser_base::skip_space_and_control ( )
protected

Skip all characters that are 0-32 in ASCII range