mrdocs::parse

Parse a string view

Synopsis

Declared in <mrdocs/Support/Parse.hpp>

template<HasParse T>
Expected<T>
parse(std::string_view sv);

Description

Parse a string view sv as an object of type T. If parsing fails, the function returns an error.

This overload does not return the ParseResult object containing the pointer to the first character not parsed. Instead, the position of the error is calculated and the error message is formatted with the error position.

This function parses a string view sv into a value of type T. The function calls the parse function for the type T with the sv.data() and sv.data() + sv.size() as the first and last pointers, respectively.

If the parse function returns an error, then the function returns the error.

If the parse function returns success, but there are characters left in the string view, then the function returns an error with the message "trailing characters".

Otherwise, it returns the value.

Return Value

A container holding an error or a value.

Parameters

Name Description

sv

The string view to parse

Created with MrDocs