REAL
Regular Expression Algorithmic Library — constexpr C++20 regex
Loading...
Searching...
No Matches
real::basic_match_result< SlotStorage > Class Template Reference

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<bool Cascade, typename Vm >
constexpr bool engine_refill (Vm &vm, std::string_view text, std::size_t pos, detail::run_mode mode, std::size_t forbid, std::string_view pattern, std::span< const detail::named_group > names)
 Engine-internal: re-run the search into this result's OWN slot buffer, reusing its capacity. Not part of the public API.
 
constexpr void bind_context (std::string_view text, std::string_view pattern, std::span< const detail::named_group > names)
 Binds the invariant context (subject, pattern, named groups) once. For an iterator that refills the same result many times, these never change within a walk — set them here, 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 for an iterator whose context is already bound via bind_context runs the VM and records only the outcome (the invariant fields are already set), the find_iter hot path.
 
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::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.
 

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_groupnames_
 Borrowed named-group table.
 

Detailed Description

template<typename SlotStorage>
class real::basic_match_result< SlotStorage >

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 on the regex are deleted to catch the common dangling mistake at compile time. Named-group lookups reference the regex's name table, so the regex must outlive the result too.

Template Parameters
SlotStorageThe capture-slot container (vector- or static-backed), supplied by the storage policy.

Definition at line 39 of file real.hpp.

Constructor & Destructor Documentation

◆ basic_match_result() [1/2]

template<typename SlotStorage >
constexpr real::basic_match_result< SlotStorage >::basic_match_result ( )
constexprdefault

Constructs an empty (non-matched) result.

◆ basic_match_result() [2/2]

template<typename SlotStorage >
constexpr real::basic_match_result< SlotStorage >::basic_match_result ( std::string_view  text,
SlotStorage  slots,
bool  matched,
std::string_view  pattern,
std::span< const detail::named_group names 
)
inlineconstexpr

Constructs a result from raw slots (used internally by the engine).

Parameters
[in]textThe searched text (borrowed; must outlive the result).
[in]slotsFlattened capture slots (byte offsets, npos for unset).
[in]matchedWhether a match occurred.
[in]patternThe pattern text (for named-group resolution).
[in]namesThe regex's named-group table (borrowed).

Definition at line 56 of file real.hpp.

Member Function Documentation

◆ bind_context()

template<typename SlotStorage >
constexpr void real::basic_match_result< SlotStorage >::bind_context ( std::string_view  text,
std::string_view  pattern,
std::span< const detail::named_group names 
)
inlineconstexpr

Binds the invariant context (subject, pattern, named groups) once. For an iterator that refills the same result many times, these never change within a walk — set them here, not per match.

Definition at line 108 of file real.hpp.

◆ end() [1/2]

template<typename SlotStorage >
constexpr std::size_t real::basic_match_result< SlotStorage >::end ( std::size_t  group = 0) const
inlineconstexpr

End byte offset (exclusive) of a group.

Parameters
[in]groupGroup number (0 = whole match).
Returns
The offset, or real::npos if the group did not participate.

Definition at line 169 of file real.hpp.

◆ end() [2/2]

template<typename SlotStorage >
constexpr std::size_t real::basic_match_result< SlotStorage >::end ( std::string_view  name) const
inlineconstexpr

Returns its end offset, or npos if unknown.

Parameters
[in]nameGroup name.
Returns
Its end offset, or npos if unknown.

Definition at line 218 of file real.hpp.

◆ engine_refill()

template<typename SlotStorage >
template<bool Cascade, typename Vm >
constexpr bool real::basic_match_result< SlotStorage >::engine_refill ( Vm &  vm,
std::string_view  text,
std::size_t  pos,
detail::run_mode  mode,
std::size_t  forbid,
std::string_view  pattern,
std::span< const detail::named_group names 
)
inlineconstexpr

Engine-internal: re-run the search into this result's OWN slot buffer, reusing its capacity. Not part of the public API.

The match iterator holds one result and refreshes it in place each step. vm.run fills the slots via assign, which reuses the existing capacity, so a match-dense iteration allocates the slot vector once instead of once per match — the measured per-match cost (a fresh allocation is ~5x a reused one). A user-held copy of a previous match stays independent: copying a result deep-copies its slots, so refilling this one never disturbs it.

Template Parameters
CascadeSelect the OPT-C memchr-cascade class-run variant (chosen once per walk).
VmThe Pike VM type (kept a template to avoid a header cycle).
Parameters
[in]vmThe VM to run.
[in]textThe searched text (borrowed).
[in]posStart offset for the search.
[in]modeThe run mode.
[in]forbidThe empty-match forbid-until offset.
[in]patternThe pattern text (for named-group resolution).
[in]namesThe regex's named-group table (borrowed).
Returns
Whether a match occurred.

Definition at line 90 of file real.hpp.

◆ engine_refill_hot()

template<typename SlotStorage >
template<bool Cascade, typename Vm >
constexpr bool real::basic_match_result< SlotStorage >::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 
)
inlineconstexpr

Per-match refill for an iterator whose context is already bound via bind_context runs the VM and records only the outcome (the invariant fields are already set), the find_iter hot path.

Definition at line 120 of file real.hpp.

◆ group_index()

template<typename SlotStorage >
constexpr std::size_t real::basic_match_result< SlotStorage >::group_index ( std::string_view  name) const
inlineconstexpr

Resolves a group name to its number.

Parameters
[in]nameThe group name.
Returns
The group number, or real::npos if unknown.

Definition at line 190 of file real.hpp.

◆ matched()

template<typename SlotStorage >
constexpr bool real::basic_match_result< SlotStorage >::matched ( ) const
inlineconstexpr

Returns true if the attempt matched.

Definition at line 134 of file real.hpp.

◆ operator bool()

template<typename SlotStorage >
constexpr real::basic_match_result< SlotStorage >::operator bool ( ) const
inlineexplicitconstexpr

Returns true if the attempt matched (explicit bool conversion).

Definition at line 142 of file real.hpp.

◆ operator[]() [1/2]

template<typename SlotStorage >
constexpr std::string_view real::basic_match_result< SlotStorage >::operator[] ( std::size_t  group) const
inlineconstexpr

View of a group's matched text.

Parameters
[in]groupGroup number (0 = whole match).
Returns
A view into the searched text, empty if the group is unset.

Definition at line 179 of file real.hpp.

◆ operator[]() [2/2]

template<typename SlotStorage >
constexpr std::string_view real::basic_match_result< SlotStorage >::operator[] ( std::string_view  name) const
inlineconstexpr

Returns its matched text, empty if unknown/unset.

Parameters
[in]nameGroup name.
Returns
Its matched text, empty if unknown/unset.

Definition at line 229 of file real.hpp.

◆ size()

template<typename SlotStorage >
constexpr std::size_t real::basic_match_result< SlotStorage >::size ( ) const
inlineconstexpr

Returns the number of groups, including group 0 (the whole match).

Definition at line 149 of file real.hpp.

◆ start() [1/2]

template<typename SlotStorage >
constexpr std::size_t real::basic_match_result< SlotStorage >::start ( std::size_t  group = 0) const
inlineconstexpr

Start byte offset of a group.

Parameters
[in]groupGroup number (0 = whole match).
Returns
The offset, or real::npos if the group did not participate.

Definition at line 159 of file real.hpp.

◆ start() [2/2]

template<typename SlotStorage >
constexpr std::size_t real::basic_match_result< SlotStorage >::start ( std::string_view  name) const
inlineconstexpr

Returns its start offset, or npos if unknown.

Parameters
[in]nameGroup name.
Returns
Its start offset, or npos if unknown.

Definition at line 207 of file real.hpp.

Member Data Documentation

◆ matched_

template<typename SlotStorage >
bool real::basic_match_result< SlotStorage >::matched_ {}
private

Whether a match occurred.

Definition at line 239 of file real.hpp.

◆ names_

template<typename SlotStorage >
std::span<const detail::named_group> real::basic_match_result< SlotStorage >::names_
private

Borrowed named-group table.

Definition at line 241 of file real.hpp.

◆ pattern_

template<typename SlotStorage >
std::string_view real::basic_match_result< SlotStorage >::pattern_
private

Pattern text (for named lookups).

Definition at line 240 of file real.hpp.

◆ slots_

template<typename SlotStorage >
SlotStorage real::basic_match_result< SlotStorage >::slots_
private

Flattened capture slots.

Definition at line 238 of file real.hpp.

◆ text_

template<typename SlotStorage >
std::string_view real::basic_match_result< SlotStorage >::text_
private

The searched text.

Definition at line 237 of file real.hpp.


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