Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
donner::css::AttributeSelector Struct Reference

Selectors which match against element attributes, such as a[href^="https://"] or h1[title]. More...

#include "donner/css/selectors/AttributeSelector.h"

Collaboration diagram for donner::css::AttributeSelector:
[legend]

Classes

struct  Matcher
 Matcher condition for an attribute selector. More...
 

Public Member Functions

 AttributeSelector (WqName name)
 Create an AttributeSelector with the given name.
 
 ~AttributeSelector () noexcept=default
 Destructor.
 
 AttributeSelector (AttributeSelector &&) noexcept=default
 Move constructor.
 
AttributeSelectoroperator= (AttributeSelector &&) noexcept=default
 Move assignment operator.
 
 AttributeSelector (const AttributeSelector &) noexcept=default
 Copy constructor.
 
AttributeSelectoroperator= (const AttributeSelector &) noexcept=default
 Copy assignment operator.
 
bool isValid () const
 Returns true if this is a valid selector.
 
template<ElementLike T>
bool matches (const T &element) const
 Returns true if the provided element matches this selector.
 

Public Attributes

WqName name
 Attribute name.
 
std::optional< Matchermatcher
 Optional matcher condition. If this is not specified, the attribute existing is sufficient for a match.
 

Friends

std::ostream & operator<< (std::ostream &os, const AttributeSelector &obj)
 Ostream output operator, which outputs a debug string, e.g. AttributeSelector(name Eq(=) value)
 

Detailed Description

Selectors which match against element attributes, such as a[href^="https://"] or h1[title].

See https://www.w3.org/TR/selectors-4/#attribute-selectors for the full definition.

Attribute selectors start with a square bracket, specify an attribute name, and an optional Matcher condition to allow matching against the attribute contents.


Class Documentation

◆ donner::css::AttributeSelector::Matcher

struct donner::css::AttributeSelector::Matcher

Matcher condition for an attribute selector.

This is set when the selector includes a match operator, such as ^= or =, and includes a string and an optional case-insensitive flag.

For a standard case-sensitive matcher, this appears in the source as:

[attr="value"]

For a case-insensitive matcher, an "i" suffix is added:

[attr="value" i]
Collaboration diagram for donner::css::AttributeSelector::Matcher:
[legend]
Class Members
bool caseInsensitive = false Whether to match case-insensitively.
AttrMatcher op The match operator.
RcString value The value to match against.

Constructor & Destructor Documentation

◆ AttributeSelector()

donner::css::AttributeSelector::AttributeSelector ( WqName name)
inlineexplicit

Create an AttributeSelector with the given name.

Parameters
nameThe attribute name.

Member Function Documentation

◆ matches()

template<ElementLike T>
bool donner::css::AttributeSelector::matches ( const T & element) const
inline

Returns true if the provided element matches this selector.

Parameters
elementThe element to check.

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