|
REAL
Regular Expression Algorithmic Library — constexpr C++20 regex
|
The result of a match attempt: success, spans and captures. More...
#include <real.hpp>
Public Member Functions | |
| constexpr | basic_match_result ()=default |
| Constructs an empty (non-matched) result. | |
| constexpr | basic_match_result (std::string_view text, SlotStorage &&slots, bool matched, std::string_view pattern, std::span< const detail::named_group > names) |
| Constructs a result from raw slots (used internally by the engine). | |
| template<typename OtherOwner > requires (!std::is_same_v<OtherOwner, NameOwner>) | |
| constexpr | basic_match_result (basic_match_result< SlotStorage, OtherOwner > other) |
| Engine-internal: adopts the fields of the borrowing twin, to be detached next. | |
| constexpr | basic_match_result (std::string_view text, std::string_view pattern, std::span< const detail::named_group > names) |
| Engine-internal: an empty, unmatched result whose slot storage is built IN PLACE. | |
| constexpr SlotStorage & | engine_slots () noexcept |
| Engine-internal: the slot storage, for the engine to fill in place. | |
| constexpr void | engine_set_matched (bool matched) noexcept |
| Engine-internal: records whether the fill that just ran produced a match. | |
| constexpr void | detach_from_regex () |
| Engine-internal: stop borrowing the regex's name tables, because it is about to die. | |
| constexpr void | bind_context (std::string_view text, std::string_view pattern, std::span< const detail::named_group > names) |
| Binds the subject, pattern and named groups once per walk, not per match. | |
| template<bool Cascade, typename Vm > | |
| constexpr bool | engine_refill_hot (Vm &vm, std::string_view text, std::size_t pos, detail::run_mode mode, std::size_t forbid, match_semantics sem=match_semantics::first) |
| Per-match refill after bind_context — runs the VM and records only the outcome. | |
| template<typename Vm > | |
| constexpr void | engine_refill_span (Vm &vm, std::size_t s, std::size_t e) |
| Refill from a span the engine already found in a batch, bypassing the VM entirely. | |
| template<bool Cascade, typename Vm > | |
| constexpr bool | engine_refill_trailing_la (Vm &vm, std::string_view text, std::size_t pos) |
| Cold path for a trailing-lookaround walk. | |
| constexpr bool | matched () const |
Returns true if the attempt matched. | |
| constexpr | operator bool () const |
Returns true if the attempt matched (explicit bool conversion). | |
| constexpr std::size_t | size () const |
| Returns the number of groups, including group 0 (the whole match). | |
| constexpr std::size_t | start (std::size_t group=0) const |
| Start byte offset of a group. | |
| constexpr std::size_t | end (std::size_t group=0) const |
| End byte offset (exclusive) of a group. | |
| constexpr std::string_view | operator[] (std::size_t group) const |
| View of a group's matched text. | |
| constexpr std::string_view | str (std::size_t group=0) const |
View of a group's matched text — std::smatch's spelling for operator[]. | |
| constexpr std::size_t | group_index (std::string_view name) const |
| Resolves a group name to its number. | |
| constexpr std::size_t | start (std::string_view name) const |
| Returns its start offset, or npos if unknown. | |
| constexpr std::size_t | end (std::string_view name) const |
| Returns its end offset, or npos if unknown. | |
| constexpr std::string_view | operator[] (std::string_view name) const |
| Returns its matched text, empty if unknown/unset. | |
| constexpr std::span< const std::size_t > | spans () const noexcept |
The capture slots as one flat [start0, end0, start1, end1, …] view. | |
Private Attributes | |
| std::string_view | text_ |
| The searched text. | |
| SlotStorage | slots_ |
| Flattened capture slots. | |
| bool | matched_ {} |
| Whether a match occurred. | |
| std::string_view | pattern_ |
| Pattern text (for named lookups). | |
| std::span< const detail::named_group > | names_ |
| NameOwner | owner_ {} |
Friends | |
| template<typename , typename > | |
| class | basic_match_result |
| The twin specialisation reads these fields to adopt them; nothing else does. | |
The result of a match attempt: success, spans and captures.
Group views point into the searched text, which must outlive the result (the rvalue std::string overloads are deleted). Named lookups borrow the regex's pattern and name table; a result from a temporary regex is real::basic_regex::owning_result_type, which owns them, so names still resolve. find_iter and find_all are deleted on an rvalue regex.
| SlotStorage | The capture-slot container (vector- or static-backed), from the storage policy. |
| NameOwner | How name tables are held: borrowed from a live regex, or owned. |
|
inlineconstexpr |
Constructs a result from raw slots (used internally by the engine).
| [in] | text | The searched text (borrowed; must outlive the result). |
| [in] | slots | Flattened capture slots (byte offsets, npos for unset). |
| [in] | matched | Whether a match occurred. |
| [in] | pattern | The pattern text (for named-group resolution). |
| [in] | names | The regex's named-group table (borrowed). |
|
inlineexplicitconstexpr |
Engine-internal: adopts the fields of the borrowing twin, to be detached next.
Constrained to the owning specialisation, so the borrowing one every walk yields keeps its exact type. By value: the caller hands over a prvalue, and the slots move out of the parameter.
| OtherOwner | The source's name owner, necessarily not this one's. |
| [in] | other | The freshly run result to take over. |
|
inlineconstexpr |
Engine-internal: an empty, unmatched result whose slot storage is built IN PLACE.
With engine_slots and engine_set_matched, lets basic_regex::run hand the engine the final slot storage instead of moving a filled local in (a rep movs whose fixed startup dominates a groupless call). Keep run() to a single return statement: the result is NRVO-constructed in the caller's storage.
| [in] | text | The searched text (borrowed; must outlive the result). |
| [in] | pattern | The pattern text (for named-group resolution). |
| [in] | names | The regex's named-group table (borrowed). |
|
inlineconstexpr |
Binds the subject, pattern and named groups once per walk, not per match.
| [in] | text | The subject the walk runs over. |
| [in] | pattern | The pattern text, for diagnostics and group naming. |
| [in] | names | The pattern's named groups. |
|
inlineconstexpr |
Engine-internal: stop borrowing the regex's name tables, because it is about to die.
Copies the pattern and name table group_index reads into the result, which may outlive a temporary regex. The views are cleared either way, so owner_ is the source of truth and a copy deep-copies rather than inheriting views into the original. A no-op when the names are borrowed.
|
inlineconstexpr |
End byte offset (exclusive) of a group.
| [in] | group | Group number (0 = whole match). |
|
inlineconstexpr |
Returns its end offset, or npos if unknown.
| [in] | name | Group name. |
|
inlineconstexpr |
Per-match refill after bind_context — runs the VM and records only the outcome.
| Cascade | Whether the VM may take its memchr-cascade tail. |
| Vm | The engine type, deduced. |
| [in,out] | vm | The engine to run. |
| [in] | text | The subject. |
| [in] | pos | Byte offset to attempt at. |
| [in] | mode | Anchoring: full, prefix or search. |
| [in] | forbid | Offset at which a zero-length match is refused (the find_iter no-progress rule). |
| [in] | sem | Leftmost-first or leftmost-longest. |
|
inlineconstexpr |
Refill from a span the engine already found in a batch, bypassing the VM entirely.
| Vm | The engine type, deduced. |
| [in,out] | vm | The engine, used only to reconstruct the slot layout for this span. |
| [in] | s | Match start. |
| [in] | e | Match end. |
|
inlineconstexpr |
Cold path for a trailing-lookaround walk.
| Cascade | Whether the VM may take its memchr-cascade tail. |
| Vm | The engine type, deduced. |
| [in,out] | vm | The engine to run. |
| [in] | text | The subject. |
| [in] | pos | Byte offset to attempt at. |
|
inlineconstexprnoexcept |
Engine-internal: records whether the fill that just ran produced a match.
| [in] | matched | Whether a match occurred. |
|
inlineconstexprnoexcept |
Engine-internal: the slot storage, for the engine to fill in place.
|
inlineconstexpr |
Resolves a group name to its number.
| [in] | name | The group name. |
|
inlineconstexpr |
Returns true if the attempt matched.
|
inlineexplicitconstexpr |
Returns true if the attempt matched (explicit bool conversion).
|
inlineconstexpr |
View of a group's matched text.
| [in] | group | Group number (0 = whole match). |
|
inlineconstexpr |
Returns its matched text, empty if unknown/unset.
| [in] | name | Group name. |
|
inlineconstexpr |
Returns the number of groups, including group 0 (the whole match).
|
inlineconstexprnoexcept |
The capture slots as one flat [start0, end0, start1, end1, …] view.
For copying every group in one pass, pairwise (spans[2g], spans[2g+1]); the C ABI's spans buffer has this layout. Only meaningful on a matched result: an unmatched one carries whatever the last fill left. For a single group prefer start / end.
2 * size() slot values; empty when there are no slots.
|
inlineconstexpr |
Start byte offset of a group.
| [in] | group | Group number (0 = whole match). |
|
inlineconstexpr |
Returns its start offset, or npos if unknown.
| [in] | name | Group name. |
|
inlineconstexpr |
View of a group's matched text — std::smatch's spelling for operator[].
Unlike std::smatch::str it returns a view: it never copies, and the subject must outlive the result. std::string s = m.str(1); does not compile (the conversion is explicit); write std::string s {m.str(1)}; for an owned copy.
| [in] | group | Group number (0 = whole match). |
|
private |
Named-group table: borrowed, or owned via owner_.
|
private |
Owns what pattern_ and names_ point at, once detach_from_regex has run; empty (and zero-sized) on the compile-time policy, null on every result that borrows.