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}).
 
 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}).
 
template<std::size_t N>
 regex_token_iterator (BidirIt first, BidirIt last, const regex_type &re, const int(&submatches)[N], regex_constants::match_flag_type flags=regex_constants::match_default)
 Selects the fields of a C array (e.g. const int fields[] {1, 2}).
 
 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.
 
 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)=delete
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<std::size_t N>
 regex_token_iterator (BidirIt first, BidirIt last, const regex_type &&re, const int(&submatches)[N], 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_iterator & operator++ ()
 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, whose routing it inherits. Per match it yields the requested fields in order: N >= 0 is group N (unmatched when the group took no part), -1 the match's prefix, the text since the previous match. As in std, a final -1 field yields the last suffix only if it is non-empty, while an empty field between adjacent matches is produced; with no match at all, -1 yields the whole sequence as one token.

Template Parameters
BidirItA bidirectional iterator into the searched sequence.

Constructor & Destructor Documentation

◆ regex_token_iterator() [1/4]

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/4]

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}).

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/4]

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.

◆ regex_token_iterator() [4/4]

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

Selects the fields of a C array (e.g. const int fields[] {1, 2}).

Template Parameters
NThe number of fields.
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: