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

Enumerates selected sub-matches (or the text between matches) — std::regex_token_iterator. More...

#include <regex_iter.hpp>

Collaboration diagram for real::compat::regex_token_iterator< BidirIt, CharT, Traits >:
[legend]

Public Types

using regex_type = basic_regex< CharT, Traits >
 The pattern type.
 
using value_type = sub_match< BidirIt >
 Yielded token.
 
using difference_type = std::ptrdiff_t
 Iterator traits.
 
using pointer = const value_type *
 Arrow type.
 
using reference = const value_type &
 Dereference type.
 
using iterator_category = std::forward_iterator_tag
 std::regex_token_iterator parity.
 

Public Member Functions

 regex_token_iterator ()=default
 Constructs the end sentinel.
 
 regex_token_iterator (BidirIt first, BidirIt last, const regex_type &re, int submatch=0, regex_constants::match_flag_type flags=regex_constants::match_default)
 Selects a single sub-match field (0 = whole match, N = group N, -1 = split).
 
 regex_token_iterator (BidirIt first, BidirIt last, const regex_type &re, const std::vector< int > &submatches, regex_constants::match_flag_type flags=regex_constants::match_default)
 Selects a list of fields, cycled per match (e.g. {1, 2}, {-1}). The match flags are forwarded to the wrapped regex_iterator, so the nullable/honors routing is inherited.
 
 regex_token_iterator (BidirIt first, BidirIt last, const regex_type &re, std::initializer_list< int > submatches, regex_constants::match_flag_type flags=regex_constants::match_default)
 Selects a list of fields from a braced list (e.g. {-1}).
 
 regex_token_iterator (BidirIt first, BidirIt last, const regex_type &&re, int submatch=0, regex_constants::match_flag_type flags=regex_constants::match_default)=delete
 Constructing from a temporary regex would dangle (std::regex_token_iterator parity).
 
 regex_token_iterator (BidirIt first, BidirIt last, const regex_type &&re, const std::vector< int > &submatches, regex_constants::match_flag_type flags=regex_constants::match_default)=delete
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
reference operator* () const
 The current token.
 
pointer operator-> () const
 The current token.
 
regex_token_iteratoroperator++ ()
 Advances to the next token, becoming the end sentinel when the fields are exhausted.
 
regex_token_iterator operator++ (int)
 Advances to the next token, returning the previous position.
 
bool operator== (const regex_token_iterator &other) const
 Equality. Two non-end iterators compare equal only for the same underlying walk, field selectors, field index, suffix state and current token.
 
bool operator!= (const regex_token_iterator &other) const
 Inequality, the negation of operator==.
 

Private Member Functions

void set_field ()
 Computes the current token from the current match and subs_[n_].
 
void init (BidirIt first, BidirIt last)
 Establishes the first token (or the whole-sequence token when there is no match).
 

Private Attributes

regex_iterator< BidirIt, CharT, Traits > position_
 The underlying match walk.
 
std::vector< int > subs_
 Field selectors, cycled per match.
 
std::size_t n_ {0}
 Current field index into subs_.
 
value_type current_
 Current token (by value — no aliasing).
 
bool has_m1_ {false}
 Whether a -1 (split) field is present.
 
bool suffix_mode_ {false}
 Emitting the trailing split suffix.
 
bool at_end_ {true}
 End-of-sequence.
 

Detailed Description

template<typename BidirIt, typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
class real::compat::regex_token_iterator< BidirIt, CharT, Traits >

Enumerates selected sub-matches (or the text between matches) — std::regex_token_iterator.

Wraps regex_iterator, so it inherits the per-operation nullable routing untouched (it never replays the engine choice). For each match it yields the requested fields in order: a field N >= 0 is capture group N (a non-participating group yields an empty matched == false token); the field -1 is the text before this match since the previous one — i.e. the match's prefix() — which turns -1 into a splitter. After the last match, a trailing -1 field yields the final suffix iff it is non-empty (std's rule; an empty field between adjacent matches is still produced, the asymmetry std pins). With -1 and no match at all, the whole sequence is the single token.

Template Parameters
BidirItA contiguous iterator into the searched sequence.

Constructor & Destructor Documentation

◆ regex_token_iterator() [1/3]

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
real::compat::regex_token_iterator< BidirIt, CharT, Traits >::regex_token_iterator ( BidirIt  first,
BidirIt  last,
const regex_type re,
int  submatch = 0,
regex_constants::match_flag_type  flags = regex_constants::match_default 
)
inline

Selects a single sub-match field (0 = whole match, N = group N, -1 = split).

Parameters
[in]firstStart of the character sequence.
[in]lastEnd of the character sequence.
[in]reThe pattern; it must outlive this iterator.
[in]submatchThe field to yield per match.
[in]flagsMatch flags, defaulting to regex_constants::match_default.

◆ regex_token_iterator() [2/3]

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
real::compat::regex_token_iterator< BidirIt, CharT, Traits >::regex_token_iterator ( BidirIt  first,
BidirIt  last,
const regex_type re,
const std::vector< int > &  submatches,
regex_constants::match_flag_type  flags = regex_constants::match_default 
)
inline

Selects a list of fields, cycled per match (e.g. {1, 2}, {-1}). The match flags are forwarded to the wrapped regex_iterator, so the nullable/honors routing is inherited.

Parameters
[in]firstStart of the character sequence.
[in]lastEnd of the character sequence.
[in]reThe pattern; it must outlive this iterator.
[in]submatchesThe fields to cycle through; an empty list is treated as {0}.
[in]flagsMatch flags, defaulting to regex_constants::match_default.

◆ regex_token_iterator() [3/3]

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
real::compat::regex_token_iterator< BidirIt, CharT, Traits >::regex_token_iterator ( BidirIt  first,
BidirIt  last,
const regex_type re,
std::initializer_list< int >  submatches,
regex_constants::match_flag_type  flags = regex_constants::match_default 
)
inline

Selects a list of fields from a braced list (e.g. {-1}).

Parameters
[in]firstStart of the character sequence.
[in]lastEnd of the character sequence.
[in]reThe pattern; it must outlive this iterator.
[in]submatchesThe fields to cycle through.
[in]flagsMatch flags, defaulting to regex_constants::match_default.

Member Function Documentation

◆ init()

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
void real::compat::regex_token_iterator< BidirIt, CharT, Traits >::init ( BidirIt  first,
BidirIt  last 
)
inlineprivate

Establishes the first token (or the whole-sequence token when there is no match).

Parameters
[in]firstStart of the character sequence.
[in]lastEnd of the character sequence.

◆ operator!=()

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
bool real::compat::regex_token_iterator< BidirIt, CharT, Traits >::operator!= ( const regex_token_iterator< BidirIt, CharT, Traits > &  other) const
inline

Inequality, the negation of operator==.

Parameters
[in]otherThe iterator to compare against.
Returns
Whether the two denote different iteration positions.

◆ operator*()

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
reference real::compat::regex_token_iterator< BidirIt, CharT, Traits >::operator* ( ) const
inline

The current token.

Returns
A reference to it, valid until the next increment.

◆ operator++() [1/2]

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
regex_token_iterator & real::compat::regex_token_iterator< BidirIt, CharT, Traits >::operator++ ( )
inline

Advances to the next token, becoming the end sentinel when the fields are exhausted.

Returns
*this.

◆ operator++() [2/2]

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
regex_token_iterator real::compat::regex_token_iterator< BidirIt, CharT, Traits >::operator++ ( int  )
inline

Advances to the next token, returning the previous position.

Returns
A copy of *this as it was before the increment.

◆ operator->()

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
pointer real::compat::regex_token_iterator< BidirIt, CharT, Traits >::operator-> ( ) const
inline

The current token.

Returns
A pointer to it, valid until the next increment.

◆ operator==()

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
bool real::compat::regex_token_iterator< BidirIt, CharT, Traits >::operator== ( const regex_token_iterator< BidirIt, CharT, Traits > &  other) const
inline

Equality. Two non-end iterators compare equal only for the same underlying walk, field selectors, field index, suffix state and current token.

Parameters
[in]otherThe iterator to compare against.
Returns
Whether the two denote the same iteration position.

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