REAL
Regular Expression Algorithmic Library — constexpr C++20 regex
Loading...
Searching...
No Matches
real::compat::match_results< BidirIt, Alloc > Class Template Reference

The result of a match: group sub-matches plus the prefix and suffix. More...

#include <regex_match.hpp>

Public Types

using value_type = sub_match< BidirIt >
 Element type.
 
using const_reference = const value_type &
 Reference type.
 
using reference = value_type &
 Reference type.
 
using const_iterator = typename std::vector< value_type, Alloc >::const_iterator
 Iterator.
 
using iterator = const_iterator
 Iterators are const (std parity).
 
using difference_type = typename std::iterator_traits< BidirIt >::difference_type
 Distance type.
 
using size_type = std::size_t
 Size type.
 
using char_type = typename std::iterator_traits< BidirIt >::value_type
 Character type.
 
using string_type = std::basic_string< char_type >
 Owning string type.
 

Public Member Functions

bool ready () const noexcept
 Whether a successful match has been stored.
 
size_type size () const noexcept
 Number of marks (groups), including group 0; 0 when there was no match.
 
bool empty () const noexcept
 Whether there are no marks at all.
 
const_reference operator[] (size_type n) const
 The sub-match for group n (group 0 is the whole match). Out-of-range n returns a reference to an unmatched sub_match anchored at the sequence end {last_, last_, false}, exactly like std::match_results::operator[] (verified on libc++ and libstdc++) — never out-of-bounds. A token selector {2}/{5} or a negative field relies on this.
 
difference_type position (size_type n=0) const
 Start offset of group n from the sequence start. For an out-of-range group std anchors the sub_match at the end, so the offset is the full sequence length.
 
difference_type length (size_type n=0) const
 Length of group n (0 if out of range or unmatched).
 
string_type str (size_type n=0) const
 Matched text of group n (empty if out of range or unmatched).
 
const value_typeprefix () const
 The unmatched prefix (sequence start up to the whole match).
 
const value_typesuffix () const
 The unmatched suffix (whole match end to sequence end).
 
const_iterator begin () const
 Iteration over the marks, group 0 first.
 
const_iterator end () const
 End of the mark range.
 
const_iterator cbegin () const
 Same as begin; the marks are const either way.
 
const_iterator cend () const
 Same as end.
 
void reset (BidirIt first, BidirIt last)
 Resets to the not-ready (no-match) state over the sequence [first, last).
 
void set_ready_no_match ()
 Marks a ready but unmatched result — after a failed search/match std leaves ready() == true with size() == 0 (a not-ready result would be a divergence).
 
void rebase_prefix (BidirIt first)
 Re-bases the unmatched prefix to start at first — for iteration, where a match's prefix runs from the previous match's end (not the sequence start). The std path already gets this from the wrapped std::regex_iterator; the real path needs it.
 
template<typename RealMatch >
void fill_from_real (const RealMatch &match)
 Fills from real's byte offsets over the sequence [first_, last_). Templated on the match type — real::regex::search returns an SBO-backed result, not the std::vector-backed real::match_result alias.
 
template<typename StdMatch >
void fill_from_std (const StdMatch &match)
 Copies from a std::match_results (the fallback path) over the same sequence.
 

Private Attributes

BidirIt first_ {}
 Start of the searched sequence.
 
BidirIt last_ {}
 End of the searched sequence.
 
std::vector< value_type, Alloc > groups_
 Group sub-matches (0 = whole match).
 
value_type prefix_ {}
 Unmatched prefix.
 
value_type suffix_ {}
 Unmatched suffix.
 
value_type unmatched_ {}
 Sentinel for out-of-range operator[] (anchored at last_).
 
bool ready_ {false}
 Whether a match is stored.
 

Detailed Description

template<typename BidirIt, typename Alloc = std::allocator<sub_match<BidirIt>>>
class real::compat::match_results< BidirIt, Alloc >

The result of a match: group sub-matches plus the prefix and suffix.

Stores both ends of the searched sequence (first_, last_) so suffix() and lengths are exact (the end is not derivable from a base pointer alone). Filled either from real's byte offsets or copied from a std::match_results on the fallback path.

Template Parameters
BidirItA contiguous iterator into the searched sequence.
AllocAllocator for the sub-match vector (std parity; default suffices).

Member Function Documentation

◆ begin()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
const_iterator real::compat::match_results< BidirIt, Alloc >::begin ( ) const
inline

Iteration over the marks, group 0 first.

Returns
An iterator to the first sub-match. Iterators are const, as in std::match_results.

◆ cbegin()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
const_iterator real::compat::match_results< BidirIt, Alloc >::cbegin ( ) const
inline

Same as begin; the marks are const either way.

Returns
An iterator to the first sub-match.

◆ cend()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
const_iterator real::compat::match_results< BidirIt, Alloc >::cend ( ) const
inline

Same as end.

Returns
One past the last sub-match.

◆ empty()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
bool real::compat::match_results< BidirIt, Alloc >::empty ( ) const
inlinenoexcept

Whether there are no marks at all.

Returns
true when size is 0, i.e. no match was stored.

◆ end()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
const_iterator real::compat::match_results< BidirIt, Alloc >::end ( ) const
inline

End of the mark range.

Returns
One past the last sub-match.

◆ fill_from_real()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
template<typename RealMatch >
void real::compat::match_results< BidirIt, Alloc >::fill_from_real ( const RealMatch &  match)
inline

Fills from real's byte offsets over the sequence [first_, last_). Templated on the match type — real::regex::search returns an SBO-backed result, not the std::vector-backed real::match_result alias.

Parameters
[in]matchThe engine's result, whose group offsets are byte offsets into the sequence.

◆ fill_from_std()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
template<typename StdMatch >
void real::compat::match_results< BidirIt, Alloc >::fill_from_std ( const StdMatch &  match)
inline

Copies from a std::match_results (the fallback path) over the same sequence.

Parameters
[in]matchThe standard library's result to copy marks, prefix and suffix from.

◆ length()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
difference_type real::compat::match_results< BidirIt, Alloc >::length ( size_type  n = 0) const
inline

Length of group n (0 if out of range or unmatched).

Parameters
[in]nGroup index; 0 is the whole match.
Returns
Its length in characters.

◆ operator[]()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
const_reference real::compat::match_results< BidirIt, Alloc >::operator[] ( size_type  n) const
inline

The sub-match for group n (group 0 is the whole match). Out-of-range n returns a reference to an unmatched sub_match anchored at the sequence end {last_, last_, false}, exactly like std::match_results::operator[] (verified on libc++ and libstdc++) — never out-of-bounds. A token selector {2}/{5} or a negative field relies on this.

Parameters
[in]nGroup index; 0 is the whole match.
Returns
That group's sub-match, or the end-anchored unmatched one when n is out of range.

◆ position()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
difference_type real::compat::match_results< BidirIt, Alloc >::position ( size_type  n = 0) const
inline

Start offset of group n from the sequence start. For an out-of-range group std anchors the sub_match at the end, so the offset is the full sequence length.

Parameters
[in]nGroup index; 0 is the whole match.
Returns
Its start offset from the sequence start.

◆ prefix()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
const value_type & real::compat::match_results< BidirIt, Alloc >::prefix ( ) const
inline

The unmatched prefix (sequence start up to the whole match).

Returns
The prefix sub-match; see rebase_prefix for what it means during iteration.

◆ ready()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
bool real::compat::match_results< BidirIt, Alloc >::ready ( ) const
inlinenoexcept

Whether a successful match has been stored.

Returns
true once a search or match has filled this object.

◆ rebase_prefix()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
void real::compat::match_results< BidirIt, Alloc >::rebase_prefix ( BidirIt  first)
inline

Re-bases the unmatched prefix to start at first — for iteration, where a match's prefix runs from the previous match's end (not the sequence start). The std path already gets this from the wrapped std::regex_iterator; the real path needs it.

Parameters
[in]firstWhere the prefix should now start — the previous match's end.

◆ reset()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
void real::compat::match_results< BidirIt, Alloc >::reset ( BidirIt  first,
BidirIt  last 
)
inline

Resets to the not-ready (no-match) state over the sequence [first, last).

Parameters
[in]firstStart of the sequence this result will describe.
[in]lastOne past its end; kept so suffix and lengths stay exact.

◆ size()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
size_type real::compat::match_results< BidirIt, Alloc >::size ( ) const
inlinenoexcept

Number of marks (groups), including group 0; 0 when there was no match.

Returns
The sub-match count.

◆ str()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
string_type real::compat::match_results< BidirIt, Alloc >::str ( size_type  n = 0) const
inline

Matched text of group n (empty if out of range or unmatched).

Parameters
[in]nGroup index; 0 is the whole match.
Returns
An owned copy of its text.

◆ suffix()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
const value_type & real::compat::match_results< BidirIt, Alloc >::suffix ( ) const
inline

The unmatched suffix (whole match end to sequence end).

Returns
The suffix sub-match.

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