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.
 
using allocator_type = Alloc
 Allocator 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.
 
size_type max_size () const noexcept
 The most marks this object could hold.
 
bool empty () const noexcept
 Whether there are no marks at all.
 
const_reference operator[] (size_type n) const
 The sub-match for group n. An out-of-range n yields an unmatched sub-match anchored at the sequence end, as libstdc++ and libc++ do; a token iterator's out-of-range selector relies on it.
 
difference_type position (size_type n=0) const
 Start offset of group n; an out-of-range group sits at the end, as in std.
 
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_type & prefix () const
 The unmatched prefix (sequence start up to the whole match).
 
const value_type & suffix () 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.
 
allocator_type get_allocator () const
 The allocator of the sub-match vector.
 
void swap (match_results &other) noexcept
 Exchanges the whole state with other.
 
template<typename OutputIter >
OutputIter format (OutputIter out, const char_type *fmt_first, const char_type *fmt_last, regex_constants::match_flag_type flags=regex_constants::format_default) const
 Writes [fmt_first, fmt_last) with its references replaced by this match's text (std::match_results::format).
 
template<typename OutputIter , typename ST , typename SA >
OutputIter format (OutputIter out, const std::basic_string< char_type, ST, SA > &fmt, regex_constants::match_flag_type flags=regex_constants::format_default) const
 format over a string format.
 
template<typename ST , typename SA >
std::basic_string< char_type, ST, SA > format (const std::basic_string< char_type, ST, SA > &fmt, regex_constants::match_flag_type flags=regex_constants::format_default) const
 format into a new string.
 
string_type format (const char_type *fmt, regex_constants::match_flag_type flags=regex_constants::format_default) const
 format of a C-string format into a new string.
 
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 the result ready but empty, as std leaves it after a failed search or match.
 
void rebase_prefix (BidirIt first)
 Starts the prefix at first, as iteration requires; the std path gets this from std::regex_iterator.
 
template<typename RealMatch >
void fill_from_real (const RealMatch &match, std::size_t lead=0)
 Fills from REAL's byte offsets over [first_, last_), from any match exposing size, start and end (an engine result, a detail::offset_match).
 
template<typename RealMatch , typename Cursor >
void fill_from_real_at (const RealMatch &match, Cursor &at, std::size_t lead=0)
 Fills from REAL's offsets into a copy of a non-contiguous [first_, last_): marks are mapped through at in increasing offset order, so the walk covers their span once whatever the group order.
 
template<typename StdMatch >
void fill_from_std (const StdMatch &match)
 Copies from a std::match_results (the fallback path) over the same sequence.
 

Private Member Functions

template<typename OutputIter >
OutputIter copy_group (OutputIter out, size_type g) const
 Copies group g's text to out, nothing when it did not take part or does not exist.
 

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.

Holds both ends of the searched sequence: the suffix's end is not derivable from a base iterator. Filled from REAL's byte offsets, or copied from a std::match_results on the std path.

Template Parameters
BidirItA bidirectional iterator into the searched sequence.
AllocAllocator for the sub-match vector.

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
A const iterator to the first sub-match, 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.

◆ copy_group()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
template<typename OutputIter >
OutputIter real::compat::match_results< BidirIt, Alloc >::copy_group ( OutputIter  out,
size_type  g 
) const
inlineprivate

Copies group g's text to out, nothing when it did not take part or does not exist.

Template Parameters
OutputIterAn output iterator over characters.
Parameters
[out]outWhere the text is written.
[in]gThe group number.
Returns
out advanced past it.

◆ 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,
std::size_t  lead = 0 
)
inline

Fills from REAL's byte offsets over [first_, last_), from any match exposing size, start and end (an engine result, a detail::offset_match).

Parameters
[in]matchThe engine's result, whose group offsets are byte offsets into the searched view.
[in]leadHow many characters the view holds before first_ (1 under match_prev_avail, the context it searched with); no match starts among them.

◆ fill_from_real_at()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
template<typename RealMatch , typename Cursor >
void real::compat::match_results< BidirIt, Alloc >::fill_from_real_at ( const RealMatch &  match,
Cursor &  at,
std::size_t  lead = 0 
)
inline

Fills from REAL's offsets into a copy of a non-contiguous [first_, last_): marks are mapped through at in increasing offset order, so the walk covers their span once whatever the group order.

Template Parameters
CursorA detail::offset_cursor over the copied sequence.
Parameters
[in]matchThe engine's result, whose offsets index the copy.
[in,out]atThe cursor; at or before the match's start, left at its last mark.
[in]leadHow many characters the copy holds before first_ (1 under match_prev_avail).

◆ 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.

◆ format() [1/4]

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
string_type real::compat::match_results< BidirIt, Alloc >::format ( const char_type *  fmt,
regex_constants::match_flag_type  flags = regex_constants::format_default 
) const
inline

format of a C-string format into a new string.

Parameters
[in]fmtThe NUL-terminated format.
[in]flagsformat_sed selects sed's rules.
Returns
The expanded format.
Precondition
ready()

◆ format() [2/4]

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
template<typename ST , typename SA >
std::basic_string< char_type, ST, SA > real::compat::match_results< BidirIt, Alloc >::format ( const std::basic_string< char_type, ST, SA > &  fmt,
regex_constants::match_flag_type  flags = regex_constants::format_default 
) const
inline

format into a new string.

Template Parameters
STThe format's traits.
SAThe format's allocator.
Parameters
[in]fmtThe format.
[in]flagsformat_sed selects sed's rules.
Returns
The expanded format.
Precondition
ready()

◆ format() [3/4]

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
template<typename OutputIter >
OutputIter real::compat::match_results< BidirIt, Alloc >::format ( OutputIter  out,
const char_type *  fmt_first,
const char_type *  fmt_last,
regex_constants::match_flag_type  flags = regex_constants::format_default 
) const
inline

Writes [fmt_first, fmt_last) with its references replaced by this match's text (std::match_results::format).

ECMAScript rules: a dollar followed by a dollar, an ampersand, a backtick, a quote or one or two digits inserts a dollar, the match, the prefix, the suffix or that group (nothing for a group that does not exist); any other dollar is itself. $0 reads as the native std reads it. format_sed selects sed's.

Template Parameters
OutputIterAn output iterator over characters.
Parameters
[out]outWhere the result is written.
[in]fmt_firstStart of the format.
[in]fmt_lastOne past its end.
[in]flagsformat_sed selects sed's rules; the other bits are ignored.
Returns
out advanced past what was written.
Precondition
ready()

◆ format() [4/4]

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
template<typename OutputIter , typename ST , typename SA >
OutputIter real::compat::match_results< BidirIt, Alloc >::format ( OutputIter  out,
const std::basic_string< char_type, ST, SA > &  fmt,
regex_constants::match_flag_type  flags = regex_constants::format_default 
) const
inline

format over a string format.

Template Parameters
OutputIterAn output iterator over characters.
STThe format's traits.
SAThe format's allocator.
Parameters
[out]outWhere the result is written.
[in]fmtThe format.
[in]flagsformat_sed selects sed's rules.
Returns
out advanced past what was written.
Precondition
ready()

◆ get_allocator()

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

The allocator of the sub-match vector.

Returns
A copy of it.

◆ 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.

◆ max_size()

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

The most marks this object could hold.

Returns
The sub-match vector's limit.

◆ 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. An out-of-range n yields an unmatched sub-match anchored at the sequence end, as libstdc++ and libc++ do; a token iterator's out-of-range selector relies on it.

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; an out-of-range group sits at the end, as in std.

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

Starts the prefix at first, as iteration requires; the std path gets this from std::regex_iterator.

Parameters
[in]firstThe 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.

◆ swap()

template<typename BidirIt , typename Alloc = std::allocator<sub_match<BidirIt>>>
void real::compat::match_results< BidirIt, Alloc >::swap ( match_results< BidirIt, Alloc > &  other)
inlinenoexcept

Exchanges the whole state with other.

Parameters
[in,out]otherThe result to swap with.

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