A type-erased destination for one captured submatch, built implicitly from a pointer to std::string, std::string_view, bool or an arithmetic type, or from nullptr to skip the group. A submatch that does not convert fails the whole match call.
More...
#include <arg.hpp>
|
|
using | Parser = bool(*)(const char *text, std::size_t length, void *dest) |
| | Writes the [text, text + length) submatch into dest, or fails.
|
| |
|
|
constexpr | Arg () noexcept |
| | Default-constructs a no-op Arg (same as Arg(nullptr)).
|
| |
|
constexpr | Arg (std::nullptr_t) noexcept |
| | From nullptr — skips this submatch (always "succeeds", writes nothing).
|
| |
| template<typename T > |
| | Arg (T *dest) noexcept |
| | From a destination pointer — the common case (&i, &s, &d, …).
|
| |
| constexpr | Arg (void *dest, Parser parser) noexcept |
| | From an explicit destination and parser — the escape hatch for a custom radix or a caller-supplied type not covered by the T* constructor.
|
| |
| bool | parse (const char *text, std::size_t length) const |
| | Parses [text, text + length) into the destination.
|
| |
|
| static bool | parse_nothing (const char *, std::size_t, void *) |
| | The nullptr-destination parser: always succeeds, writes nothing.
|
| |
| static bool | parse_bool (const char *text, std::size_t length, bool &out) |
| | Parses into a bool: "1"/"true" -> true, "0"/"false" -> false, else fails.
|
| |
| template<typename T > |
| static bool | parse_integral (const char *text, std::size_t length, T &out) |
| | Parses into an integral type, base 10, locale-free. As RE2's strtol-based parse, one leading + is accepted (std::from_chars alone rejects it) and a - on an unsigned destination is not.
|
| |
| template<typename T > |
| static bool | parse_floating (const char *text, std::size_t length, T &out) |
| | Parses into a floating-point type with the strto* matching T, on a NUL-terminated copy.
|
| |
| template<typename T > |
| static bool | parse_into (const char *text, std::size_t length, void *dest) |
| | Dispatches to the parser for T — the function stored as this Arg's Parser.
|
| |
|
|
void * | dest_ |
| | The type-erased destination (nullptr = skip this submatch).
|
| |
|
Parser | parser_ |
| | The parser to call on parse (never nullptr).
|
| |
A type-erased destination for one captured submatch, built implicitly from a pointer to std::string, std::string_view, bool or an arithmetic type, or from nullptr to skip the group. A submatch that does not convert fails the whole match call.
◆ Arg() [1/2]
template<typename T >
| real::compat::re2::Arg::Arg |
( |
T * |
dest | ) |
|
|
inlinenoexcept |
From a destination pointer — the common case (&i, &s, &d, …).
- Template Parameters
-
| T | The pointee type: std::string, std::string_view, bool, or an integral/floating-point type. |
- Parameters
-
| [in] | dest | The destination; must outlive the call this Arg is passed to. |
◆ Arg() [2/2]
| constexpr real::compat::re2::Arg::Arg |
( |
void * |
dest, |
|
|
Parser |
parser |
|
) |
| |
|
inlineconstexprnoexcept |
From an explicit destination and parser — the escape hatch for a custom radix or a caller-supplied type not covered by the T* constructor.
- Parameters
-
| [in] | dest | The destination (opaque to Arg; interpreted only by parser). |
| [in] | parser | The parser called on parse. |
◆ parse()
| bool real::compat::re2::Arg::parse |
( |
const char * |
text, |
|
|
std::size_t |
length |
|
) |
| const |
|
inline |
Parses [text, text + length) into the destination.
- Parameters
-
| [in] | text | The submatch's first byte (not necessarily NUL-terminated). |
| [in] | length | The submatch's length in bytes. |
- Returns
true on success (or a skipped/nullptr destination); false if the submatch does not convert to the destination type.
◆ parse_bool()
| static bool real::compat::re2::Arg::parse_bool |
( |
const char * |
text, |
|
|
std::size_t |
length, |
|
|
bool & |
out |
|
) |
| |
|
inlinestaticprivate |
Parses into a bool: "1"/"true" -> true, "0"/"false" -> false, else fails.
- Parameters
-
| [in] | text | The submatch's first byte. |
| [in] | length | The submatch's length in bytes. |
| [out] | out | Set on success only. |
- Returns
true on success.
◆ parse_floating()
template<typename T >
| static bool real::compat::re2::Arg::parse_floating |
( |
const char * |
text, |
|
|
std::size_t |
length, |
|
|
T & |
out |
|
) |
| |
|
inlinestaticprivate |
Parses into a floating-point type with the strto* matching T, on a NUL-terminated copy.
Not std::from_chars, whose floating-point overload some standard libraries delete. As in RE2, the C locale's decimal separator applies (under a , locale, 1,5 parses and 1.5 does not), and the function follows T: strtod into a float would narrow an out-of-range value to infinity, where strtof reports ERANGE.
- Template Parameters
-
| T | A floating-point destination type. |
- Parameters
-
| [in] | text | The submatch's first byte. |
| [in] | length | The submatch's length in bytes. |
| [out] | out | Set on success only. |
- Returns
true when the whole submatch is consumed and the value is within T's range.
◆ parse_integral()
template<typename T >
| static bool real::compat::re2::Arg::parse_integral |
( |
const char * |
text, |
|
|
std::size_t |
length, |
|
|
T & |
out |
|
) |
| |
|
inlinestaticprivate |
Parses into an integral type, base 10, locale-free. As RE2's strtol-based parse, one leading + is accepted (std::from_chars alone rejects it) and a - on an unsigned destination is not.
- Template Parameters
-
| T | An integral destination type. |
- Parameters
-
| [in] | text | The submatch's first byte. |
| [in] | length | The submatch's length in bytes. |
| [out] | out | Set on success only. |
- Returns
true on success (the whole submatch consumed, no overflow).
◆ parse_into()
template<typename T >
| static bool real::compat::re2::Arg::parse_into |
( |
const char * |
text, |
|
|
std::size_t |
length, |
|
|
void * |
dest |
|
) |
| |
|
inlinestaticprivate |
Dispatches to the parser for T — the function stored as this Arg's Parser.
- Template Parameters
-
- Parameters
-
| [in] | text | The submatch's first byte. |
| [in] | length | The submatch's length in bytes. |
| [out] | dest | The destination, reinterpreted as T*. |
- Returns
true on success.
◆ parse_nothing()
| static bool real::compat::re2::Arg::parse_nothing |
( |
const char * |
, |
|
|
std::size_t |
, |
|
|
void * |
|
|
) |
| |
|
inlinestaticprivate |
The nullptr-destination parser: always succeeds, writes nothing.
- Returns
true, unconditionally.
The documentation for this class was generated from the following file: