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

Parse a CSS selector, or list of selectors, and returns a Selector that can be matched against in the stylesheet. More...

#include "donner/css/parser/SelectorParser.h"

Static Public Member Functions

static ParseResult< SelectorParseComponents (std::span< const ComponentValue > components)
 Parse CSS selector from a list of ComponentValues, see https://www.w3.org/TR/selectors-4/#parse-selector.
 
static ParseResult< SelectorParse (std::string_view str)
 Parse CSS selector from a string.
 
static Selector ParseForgivingSelectorList (std::span< const ComponentValue > components)
 Parse a "forgiving selector list", which is a list of selectors separated by commas, with invalid selectors removed.
 
static Selector ParseForgivingRelativeSelectorList (std::span< const ComponentValue > components)
 Parse a "forgiving relative selector list", which is a list of selectors separated by commas, with invalid selectors removed.
 

Detailed Description

Parse a CSS selector, or list of selectors, and returns a Selector that can be matched against in the stylesheet.

Parses either from a string, or from the CSS intermediate representation, a list of ComponentValues.

For example, valid selectors may be "div", "div > p", "div > p:first-child", "div > p:first-child:hover", etc. See https://www.w3.org/TR/selectors-4/#parse-selector for more details.

Member Function Documentation

◆ Parse()

ParseResult< Selector > donner::css::parser::SelectorParser::Parse ( std::string_view str)
static

Parse CSS selector from a string.

Parameters
strThe string to parse.

◆ ParseComponents()

ParseResult< Selector > donner::css::parser::SelectorParser::ParseComponents ( std::span< const ComponentValue > components)
static

Parse CSS selector from a list of ComponentValues, see https://www.w3.org/TR/selectors-4/#parse-selector.

Parameters
componentsThe list of ComponentValues to parse.

◆ ParseForgivingRelativeSelectorList()

Selector donner::css::parser::SelectorParser::ParseForgivingRelativeSelectorList ( std::span< const ComponentValue > components)
static

Parse a "forgiving relative selector list", which is a list of selectors separated by commas, with invalid selectors removed.

As relative selectors, these may start with a combinator, such as > div.

These can be matched with Selector::matches with SelectorMatchOptions::relativeToElement set.

See also
https://www.w3.org/TR/selectors-4/#forgiving-selector for more details on <forgiving-relative-selector-list>.

◆ ParseForgivingSelectorList()

Selector donner::css::parser::SelectorParser::ParseForgivingSelectorList ( std::span< const ComponentValue > components)
static

Parse a "forgiving selector list", which is a list of selectors separated by commas, with invalid selectors removed.

This is different from the standard CSS behavior, where if a single selector within a list of invalid, the entire selector list is ignored.

For example, "div, p:invalid" will return a single selector, "div".

See also
https://www.w3.org/TR/selectors-4/#forgiving-selector for more details.
Parameters
componentsThe list of ComponentValues to parse.

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