libhext: C++ Library Documentation  1.0.8-3ad0ae4
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
[legend]
Collaboration diagram for hext::AttributeCapture:
Collaboration graph
[legend]

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 override
 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.

Example:
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"));
AttributeCapture(std::string attr_name, std::string result_name, std::unique_ptr< StringPipe > pipe=nullptr) noexcept
Constructs an AttributeCapture.
std::pair< std::string, std::string > ResultPair
A string-pair containing a name and a value.
Definition: Result.h:32
Example with regex:
GumboNode * node = ...; // <a href="/highway-61"></a>
"href", // attribute name
"U.S. Route" // result name
std::make_unique<RegexPipe>(boost::regex("\\d+"))
);
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 
)
noexcept

Constructs an AttributeCapture.

Parameters
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 &&  )
defaultnoexcept

Member Function Documentation

◆ capture()

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

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

Optionally applies a StringPipe to the value before returning.

Parameters
nodeA pointer to a GumboNode of type GUMBO_NODE_ELEMENT.
Returns
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= ( AttributeCapture &&  )
defaultnoexcept

◆ operator=() [2/2]

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

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