Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
SemVer::Parser Class Reference

Used to parse SemVers from strings. More...

#include <semver.h>

Public Types

enum class  Error { INVALID_NUMBER , WRONG_CHAR , END_OF_STREAM }
 Common parsing errors. More...
 

Public Member Functions

 Parser (std::string_view input)
 Create a new parser with the given string.
 
std::expected< SemVer, Errorparse ()
 Execute the parser, returning either the well-formed SemVer or a Parser::Error.
 

Private Member Functions

std::expected< void, Errorexpect (char expected)
 Expect a character to be the next in the stream.
 
std::expected< SemVer, ErrorparseVersionCore ()
 Parses a Semantic Versioning "version core" (i.e. '1.20.7') from the input stream.
 
std::expected< uint8_t, ErrorparseNumericIdentifier ()
 Parse a number from the input stream.
 
std::string_view parsePreRelease ()
 Consumes all characters up to the build-tag identifier '+' and returns them.
 

Private Attributes

std::string_view input_
 
size_t index_ = 0
 

Detailed Description

Used to parse SemVers from strings.

Member Enumeration Documentation

◆ Error

enum class SemVer::Parser::Error
strong

Common parsing errors.

Enumerator
INVALID_NUMBER 

Could not parse the numeric.

WRONG_CHAR 

Did not find the expected char.

END_OF_STREAM 

Reached end of stream while parsing.

Member Function Documentation

◆ expect()

std::expected< void, SemVer::Parser::Error > SemVer::Parser::expect ( char expected)
private

Expect a character to be the next in the stream.

Note
This consumes the character if it exists
Parameters
[in]expectedThe character to read
Returns
std::expected<void, Error> If no error, the character was successfully found
Return values
Error::WRONG_CHARThe character was not found
Error::END_OF_STREAMThe input string ran out of characters to read

◆ parseNumericIdentifier()

std::expected< uint8_t, SemVer::Parser::Error > SemVer::Parser::parseNumericIdentifier ( )
private

Parse a number from the input stream.

Technically less strict than the true SemVer grammar requires, this internally uses std::from_chars to parse the string to an int.

Returns
std::expected<uint8_t, Error> The parsed number or Error
Return values
Error::INVALID_NUMBERIf the number cannot be parsed

◆ parsePreRelease()

std::string_view SemVer::Parser::parsePreRelease ( )
private

Consumes all characters up to the build-tag identifier '+' and returns them.

Returns
std::string_view The characters found

◆ parseVersionCore()

std::expected< SemVer, SemVer::Parser::Error > SemVer::Parser::parseVersionCore ( )
private

Parses a Semantic Versioning "version core" (i.e. '1.20.7') from the input stream.

see https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions

Returns
std::expected<SemVer, Error> The well-formed Semantic Version from the core

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