Captures an HTML Element's attribute.
More...
Captures an HTML Element's attribute.
- Example:
GumboNode * node = ...;
"src",
"image"
);
if( auto result = img.capture(node) )
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.
- Example with regex:
GumboNode * node = ...;
"href",
"U.S. Route"
std::make_unique<RegexPipe>(boost::regex("\\d+"))
);
if( auto result = highway.capture(node) )
assert(*result ==
ResultPair(
"U.S. Route",
"61"));
Definition at line 62 of file AttributeCapture.h.
◆ AttributeCapture() [1/3]
hext::AttributeCapture::AttributeCapture |
( |
std::string |
attr_name, |
|
|
std::string |
result_name, |
|
|
std::unique_ptr< StringPipe > |
pipe = nullptr |
|
) |
| |
|
noexcept |
◆ AttributeCapture() [2/3]
◆ AttributeCapture() [3/3]
◆ 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
-
node | A 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]
◆ operator=() [2/2]
The documentation for this class was generated from the following file: