Donner 0.5.1
Embeddable browser-grade SVG2 engine
Loading...
Searching...
No Matches
donner::parser::ParserBase Class Reference

Base class for parsers, containing common functionality such as maintaining the current parse location, skipping whitespace, and parsing numbers. More...

#include "donner/base/parser/details/ParserBase.h"

Collaboration diagram for donner::parser::ParserBase:
[legend]

Public Member Functions

 ParserBase (std::string_view str)
 Create a new parser.

Protected Member Functions

std::string_view take (size_t count)
 Removes and returns count characters from the remaining string.
void skipWhitespace ()
 Remove whitespace characters, from the front of remaining_ if they exist, where whitespace is based on the result of isWhitespace().
void skipCommaWhitespace ()
 Remove whitespace characters and up to one ',' character from the front of remaining_ if they exist.
bool isWhitespace (char ch) const
 Returns if the character is whitespace, where whitespace is defined as being either U+000A LINE FEED, U+000D CARRIAGE RETURN, U+0009 CHARACTER TABULATION, or U+0020 SPACE.
FileOffset currentOffset (int index=0) const
 Return the location of the parser's cursor, in characters from the start of the string.
SourceRange currentRange (int startIndex, int endIndex) const
 Return a source range relative to the parser's cursor.
SourceRange rangeFrom (size_t startOffset) const
 Return a source range from an absolute start offset to the current cursor position.
size_t consumedChars () const
 Returns the number of characters consumed by the parser.
ParseResult< double > readNumber ()
 Read a number, note that this does not skip whitespace.
std::optional< ParseDiagnosticreadNumbers (std::span< double > resultStorage)
 Read resultStorage.size() numbers, separated by whitespace and an optional comma.

Protected Attributes

const std::string_view str_
 The original string.
std::string_view remaining_
 A slice of the remaining characters to parse within str_.

Detailed Description

Base class for parsers, containing common functionality such as maintaining the current parse location, skipping whitespace, and parsing numbers.

Constructor & Destructor Documentation

◆ ParserBase()

donner::parser::ParserBase::ParserBase ( std::string_view str)
explicit

Create a new parser.

Parameters
strString to parse.

Member Function Documentation

◆ currentOffset()

FileOffset donner::parser::ParserBase::currentOffset ( int index = 0) const
protected

Return the location of the parser's cursor, in characters from the start of the string.

Parameters
indexIndex of the offset relative to the cursor to return, default is 0.

◆ currentRange()

SourceRange donner::parser::ParserBase::currentRange ( int startIndex,
int endIndex ) const
protected

Return a source range relative to the parser's cursor.

Parameters
startIndexStart offset relative to the cursor (inclusive).
endIndexEnd offset relative to the cursor (exclusive).

◆ isWhitespace()

bool donner::parser::ParserBase::isWhitespace ( char ch) const
protected

Returns if the character is whitespace, where whitespace is defined as being either U+000A LINE FEED, U+000D CARRIAGE RETURN, U+0009 CHARACTER TABULATION, or U+0020 SPACE.

Parameters
chCharacter to test.

◆ rangeFrom()

SourceRange donner::parser::ParserBase::rangeFrom ( size_t startOffset) const
protected

Return a source range from an absolute start offset to the current cursor position.

Parameters
startOffsetAbsolute start offset from the beginning of the string.

◆ readNumbers()

std::optional< ParseDiagnostic > donner::parser::ParserBase::readNumbers ( std::span< double > resultStorage)
protected

Read resultStorage.size() numbers, separated by whitespace and an optional comma.

Parameters
resultStorageLocation where the numbers will be stored, the number of parameters is based on the size of the span.

◆ take()

std::string_view donner::parser::ParserBase::take ( size_t count)
protected

Removes and returns count characters from the remaining string.

Parameters
countNumber of characters to return, this must be less than remaining_.size()
Returns
std::string_view Returned string.

The documentation for this class was generated from the following file: