Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
donner::svg::parser::ListParser Class Reference

Parses a list of values conforming to the SVG comma-or-space list syntax. More...

#include "donner/svg/parser/ListParser.h"

Static Public Member Functions

template<ListParserItemCallback Fn>
static std::optional< ParseErrorParse (std::string_view value, Fn fn)
 Parses the SVG comma-or-space separated list from the given std::string_view.
 

Detailed Description

Parses a list of values conforming to the SVG comma-or-space list syntax.

This parser adheres to the rules for SVG lists, which allow items to be separated by commas, whitespace, or a mix of both. It calls a provided function for each individual item found in the list.

Grammar allows:

  • item1, item2 item3 , item4
  • Whitespace around commas is ignored.
  • Multiple spaces between items are ignored.

Invalid syntax (returns false):

  • Empty items (e.g., item1,,item2)
  • Trailing commas (e.g., item1, item2,)
  • Leading commas (e.g., , item1)

Example Usage:

std::vector<std::string_view> items;
bool success = ListParser::Parse("item1 item2, item3", [&](std::string_view item) {
items.push_back(item);
});
// success will be true, items will contain {"item1", "item2", "item3"}
A parser result, which may contain a result of type T, or an error, or both.
Definition ParseResult.h:17
static std::optional< ParseError > Parse(std::string_view value, Fn fn)
Parses the SVG comma-or-space separated list from the given std::string_view.
Definition ListParser.h:60

Member Function Documentation

◆ Parse()

template<ListParserItemCallback Fn>
static std::optional< ParseError > donner::svg::parser::ListParser::Parse ( std::string_view value,
Fn fn )
inlinestatic

Parses the SVG comma-or-space separated list from the given std::string_view.

Template Parameters
FnType of the function to call for each list item, with signature void(std::string_view).
Parameters
valueThe string_view containing the list to parse.
fnThe function to call for each parsed item.
Returns
std::nullopt on success, or a ParseError containing the reason and position of the error on failure.

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