Captures the result of applying a function to an HTML node.
More...
Captures the result of applying a function to an HTML node.
- Example:
GumboNode * node = ...;
"text"
);
if( auto result = text.capture(node) )
assert(
*result ==
ResultPair(
"text",
"5 reasons why foo is better than bar")
);
FunctionCapture(CaptureFunction func, std::string result_name, std::unique_ptr< StringPipe > pipe={}) noexcept
Constructs a FunctionCapture.
HEXT_PUBLIC const CaptureFunction TextBuiltin
A CaptureFunction that returns the text of an HTML element.
std::pair< std::string, std::string > ResultPair
A string-pair containing a name and a value.
- Example with regex:
GumboNode * node = ...;
"centimeters",
std::make_unique<RegexPipe>(boost::regex("(\\d+)cm"))
);
if( auto result = centimeters.capture(node) )
assert(*result ==
ResultPair(
"centimeters",
"25"));
HEXT_PUBLIC const CaptureFunction InnerHtmlBuiltin
A CaptureFunction that returns the inner HTML of an HTML element.
Definition at line 63 of file FunctionCapture.h.
◆ FunctionCapture() [1/3]
hext::FunctionCapture::FunctionCapture |
( |
CaptureFunction |
func, |
|
|
std::string |
result_name, |
|
|
std::unique_ptr< StringPipe > |
pipe = {} |
|
) |
| |
|
noexcept |
Constructs a FunctionCapture.
- Parameters
-
func | The function that will be applied to an HTML node. |
result_name | The name for the result that is returned from FuntionCapture::capture. |
pipe | If given, the captured value will be sent through this StringPipe before returning from capture(). |
◆ FunctionCapture() [2/3]
◆ FunctionCapture() [3/3]
◆ capture()
std::optional<ResultPair> hext::FunctionCapture::capture |
( |
const GumboNode * |
node | ) |
const |
|
overridevirtual |
Captures the result of calling a given CaptureFunction with node as its argument.
Optionally applies a StringPipe to the value before returning.
- Parameters
-
node | A pointer to a GumboNode. |
- Returns
- A pair in the form of {result_name, result_value} or an empty optional if the capture failed.
Implements hext::Capture.
◆ operator=() [1/2]
◆ operator=() [2/2]
The documentation for this class was generated from the following file: