All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
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=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
 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));

Definition at line 58 of file AttributeMatch.h.

Constructor & Destructor Documentation

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.
hext::AttributeMatch::~AttributeMatch ( )
defaultnoexcept
hext::AttributeMatch::AttributeMatch ( AttributeMatch &&  other)
defaultnoexcept
hext::AttributeMatch::AttributeMatch ( const AttributeMatch other)

Member Function Documentation

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.

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

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