libhext: C++ Library Documentation  1.0.12-3ea013c
Public Member Functions | List of all members
hext::AttributeMatch Class Referencefinal

Matches HTML elements having an HTML attribute with a certain name and, optionally, whose value is matched by a ValueTest. More...

Inheritance diagram for hext::AttributeMatch:
Inheritance graph
[legend]
Collaboration diagram for hext::AttributeMatch:
Collaboration graph
[legend]

Public Member Functions

 AttributeMatch (std::string attr_name, std::unique_ptr< ValueTest > value_test={}) noexcept
 Constructs an AttributeMatch with an optional ValueTest. More...
 
 ~AttributeMatch () noexcept override=default
 
 AttributeMatch (AttributeMatch &&other) noexcept=default
 
 AttributeMatch (const AttributeMatch &other)
 
AttributeMatchoperator= (AttributeMatch &&other) noexcept=default
 
AttributeMatchoperator= (const AttributeMatch &other)
 
bool matches (const GumboNode *node) const override
 Return true if node has an HTML attribute called attr_name (as given in the constructor). More...
 
- Public Member Functions inherited from hext::Cloneable< AttributeMatch, Match >
virtual std::unique_ptr< Matchclone () const override
 Clones objects of template type Derived and returns an owning pointer to the newly allocated Base. More...
 
- Public Member Functions inherited from hext::Match
 Match () noexcept=default
 
 Match (const Match &)=default
 
 Match (Match &&) noexcept=default
 
Matchoperator= (const Match &)=default
 
Matchoperator= (Match &&) noexcept=default
 
virtual ~Match () noexcept=default
 

Detailed Description

Matches HTML elements having an HTML attribute with a certain name and, optionally, whose value is matched by a ValueTest.

Example:
GumboNode * node_row = ...; // <td data-row=""></td>
GumboNode * node_desolation = ...; // <td data-row="desolation"></td>
// Match nodes containing an attribute called data-row
AttributeMatch attr_row(
"data-row" // attribute name
);
attr_row.matches(node_row);
attr_row.matches(node_desolation);
// Match nodes containing an attribute called data-row whose value equals
// "desolation"
AttributeMatch attr_desolation(
"data-row", // attribute name
std::make_unique<EqualsTest>("desolation") // ValueTest
);
assert(attr_desolation.matches(node_desolation));
assert(!attr_desolation.matches(node_row));
AttributeMatch(std::string attr_name, std::unique_ptr< ValueTest > value_test={}) noexcept
Constructs an AttributeMatch with an optional ValueTest.

Definition at line 59 of file AttributeMatch.h.

Constructor & Destructor Documentation

◆ AttributeMatch() [1/3]

hext::AttributeMatch::AttributeMatch ( std::string  attr_name,
std::unique_ptr< ValueTest value_test = {} 
)
explicitnoexcept

Constructs an AttributeMatch with an optional ValueTest.

Parameters
attr_nameThe name of the HTML attribute.
value_testAn optional ValueTest which, if given, must return true for the matched HTML attribute's value.

◆ ~AttributeMatch()

hext::AttributeMatch::~AttributeMatch ( )
overridedefaultnoexcept

◆ AttributeMatch() [2/3]

hext::AttributeMatch::AttributeMatch ( AttributeMatch &&  other)
defaultnoexcept

◆ AttributeMatch() [3/3]

hext::AttributeMatch::AttributeMatch ( const AttributeMatch other)

Member Function Documentation

◆ matches()

bool hext::AttributeMatch::matches ( const GumboNode *  node) const
overridevirtual

Return true if node has an HTML attribute called attr_name (as given in the constructor).

If a ValueTest was supplied, the ValueTest must return true for the attribute's value.

Parameters
nodeA pointer to a GumboNode of type GUMBO_NODE_ELEMENT.

Implements hext::Match.

◆ operator=() [1/2]

AttributeMatch& hext::AttributeMatch::operator= ( AttributeMatch &&  other)
defaultnoexcept

◆ operator=() [2/2]

AttributeMatch& hext::AttributeMatch::operator= ( const AttributeMatch other)

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