libhext: C++ Library Documentation  0.8.2-e5d504d
Public Member Functions | List of all members
hext::AttributeCapture Class Referencefinal

Captures an HTML Element's attribute. More...

Inheritance diagram for hext::AttributeCapture:
Inheritance graph
Collaboration diagram for hext::AttributeCapture:
Collaboration graph

Public Member Functions

 AttributeCapture (std::string attr_name, std::string result_name, std::unique_ptr< StringPipe > pipe=nullptr) noexcept
 Constructs an AttributeCapture. More...
 AttributeCapture (const AttributeCapture &other)
 AttributeCapture (AttributeCapture &&) noexcept=default
AttributeCaptureoperator= (const AttributeCapture &other)
AttributeCaptureoperator= (AttributeCapture &&) noexcept=default
std::optional< ResultPaircapture (const GumboNode *node) const override
 Captures an HTML element's attribute called attr_name (as given in the constructor). More...
- Public Member Functions inherited from hext::Cloneable< AttributeCapture, Capture >
virtual std::unique_ptr< Captureclone () const
 Clones objects of template type Derived and returns an owning pointer to the newly allocated Base. More...
- Public Member Functions inherited from hext::Capture
 Capture () noexcept=default
 Capture (const Capture &)=default
 Capture (Capture &&) noexcept=default
Captureoperator= (const Capture &)=default
Captureoperator= (Capture &&) noexcept=default
virtual ~Capture () noexcept=default

Detailed Description

Captures an HTML Element's attribute.

GumboNode * node = ...; // <img src="bob.jpg"/>
"src", // attribute name
"image" // result name
if( auto result = img.capture(node) )
// attribute found and captured
assert(*result == ResultPair("image", "bob.jpg"));
Example with regex:
GumboNode * node = ...; // <a href="/highway-61"></a>
"href", // attribute name
"U.S. Route" // result name
if( auto result = highway.capture(node) )
// attribute found and captured
assert(*result == ResultPair("U.S. Route", "61"));

Definition at line 62 of file AttributeCapture.h.

Constructor & Destructor Documentation

◆ AttributeCapture() [1/3]

hext::AttributeCapture::AttributeCapture ( std::string  attr_name,
std::string  result_name,
std::unique_ptr< StringPipe pipe = nullptr 

Constructs an AttributeCapture.

attr_nameThe name of the HTML attribute whose value will be captured.
result_nameThe name for the result that is returned from AttributeCapture::capture.
pipeIf given, the captured value will be sent through this StringPipe before returning from capture().

◆ AttributeCapture() [2/3]

hext::AttributeCapture::AttributeCapture ( const AttributeCapture other)

◆ AttributeCapture() [3/3]

hext::AttributeCapture::AttributeCapture ( AttributeCapture &&  )

Member Function Documentation

◆ capture()

std::optional<ResultPair> hext::AttributeCapture::capture ( const GumboNode *  node) const

Captures an HTML element's attribute called attr_name (as given in the constructor).

Optionally applies a StringPipe to the value before returning.

nodeA pointer to a GumboNode of type GUMBO_NODE_ELEMENT.
A pair in the form of {result_name, attribute_value} or an empty optional if the attribute cannot be found.

Implements hext::Capture.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

AttributeCapture& hext::AttributeCapture::operator= ( AttributeCapture &&  )

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