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

Forward iterator over the non-overlapping matches in a text. More...

#include <real.hpp>

Collaboration diagram for real::basic_match_iterator< Storage >:
[legend]

Public Types

using value_type = basic_match_result< typename Storage::slot_storage >
 Yielded match type.
 
using difference_type = std::ptrdiff_t
 Iterator traits.
 
using reference = const value_type &
 Dereference type.
 
using pointer = const value_type *
 Arrow type.
 
using iterator_category = std::forward_iterator_tag
 Multipass: copies are independent.
 

Public Member Functions

constexpr basic_match_iterator ()=default
 Constructs the end sentinel.
 
constexpr basic_match_iterator (detail::program_view prog, std::string_view pattern, std::string_view text, std::size_t start=0, match_semantics sem=match_semantics::first)
 Constructs a begin iterator and finds the first match.
 
constexpr const value_typeoperator* () const
 Returns the current match.
 
constexpr const value_typeoperator-> () const
 Returns pointer to the current match.
 
constexpr basic_match_iteratoroperator++ ()
 Advances to the next match.
 
constexpr basic_match_iterator operator++ (int)
 Advances to the next match (post-increment).
 
constexpr bool operator== (const basic_match_iterator &other) const
 Returns true if both denote the same position/end.
 

Private Member Functions

constexpr void advance ()
 Finds the next match, applying the empty-match advance rules.
 

Private Attributes

detail::program_view prog_
 The program being run.
 
std::string_view pattern_
 Pattern text (named lookups).
 
std::string_view text_
 The text being scanned.
 
std::size_t pos_ {}
 Current scan offset.
 
std::size_t forbid_empty_until_ {}
 Empty-match guard (see pike.hpp).
 
bool done_ {true}
 True once exhausted.
 
bool cascade_ {}
 OPT-C: chosen once — run the memchr-cascade class-run variant for this whole walk.
 
match_semantics sem_ {match_semantics::first}
 leftmost-first (default) or longest (find_iter_longest).
 
value_type current_
 The current match.
 
Storage::state_type state_
 VM scratch, reused across the walk.
 

Detailed Description

template<typename Storage>
class real::basic_match_iterator< Storage >

Forward iterator over the non-overlapping matches in a text.

Follows Python's empty-match rules: an empty match is yielded (even right after a non-empty one), then the scan advances by one codepoint. The regex and the text must outlive the iterator. Obtained from basic_match_range.

Template Parameters
StorageThe regex's storage policy (selects the result/scratch types).

Definition at line 259 of file real.hpp.

Member Typedef Documentation

◆ difference_type

template<typename Storage >
using real::basic_match_iterator< Storage >::difference_type = std::ptrdiff_t

Iterator traits.

Definition at line 264 of file real.hpp.

◆ iterator_category

template<typename Storage >
using real::basic_match_iterator< Storage >::iterator_category = std::forward_iterator_tag

Multipass: copies are independent.

Definition at line 267 of file real.hpp.

◆ pointer

template<typename Storage >
using real::basic_match_iterator< Storage >::pointer = const value_type*

Arrow type.

Definition at line 266 of file real.hpp.

◆ reference

template<typename Storage >
using real::basic_match_iterator< Storage >::reference = const value_type&

Dereference type.

Definition at line 265 of file real.hpp.

◆ value_type

template<typename Storage >
using real::basic_match_iterator< Storage >::value_type = basic_match_result<typename Storage::slot_storage>

Yielded match type.

Definition at line 263 of file real.hpp.

Constructor & Destructor Documentation

◆ basic_match_iterator() [1/2]

template<typename Storage >
constexpr real::basic_match_iterator< Storage >::basic_match_iterator ( )
constexprdefault

Constructs the end sentinel.

◆ basic_match_iterator() [2/2]

template<typename Storage >
constexpr real::basic_match_iterator< Storage >::basic_match_iterator ( detail::program_view  prog,
std::string_view  pattern,
std::string_view  text,
std::size_t  start = 0,
match_semantics  sem = match_semantics::first 
)
inlineconstexpr

Constructs a begin iterator and finds the first match.

Parameters
[in]progThe compiled program to run.
[in]patternThe pattern text (for named-group resolution).
[in]textThe text to iterate over (borrowed).
[in]startByte offset to begin iterating from (0 = the whole text).
[in]semMatch semantics: leftmost-first (default) or the experimental leftmost-longest.

Definition at line 282 of file real.hpp.

Member Function Documentation

◆ advance()

template<typename Storage >
constexpr void real::basic_match_iterator< Storage >::advance ( )
inlineconstexprprivate

Finds the next match, applying the empty-match advance rules.

Definition at line 365 of file real.hpp.

◆ operator*()

template<typename Storage >
constexpr const value_type & real::basic_match_iterator< Storage >::operator* ( ) const
inlineconstexpr

Returns the current match.

Definition at line 305 of file real.hpp.

◆ operator++() [1/2]

template<typename Storage >
constexpr basic_match_iterator & real::basic_match_iterator< Storage >::operator++ ( )
inlineconstexpr

Advances to the next match.

Returns
*this.

Definition at line 322 of file real.hpp.

◆ operator++() [2/2]

template<typename Storage >
constexpr basic_match_iterator real::basic_match_iterator< Storage >::operator++ ( int  )
inlineconstexpr

Advances to the next match (post-increment).

Returns
A copy of the iterator at its pre-increment position.

Definition at line 332 of file real.hpp.

◆ operator->()

template<typename Storage >
constexpr const value_type * real::basic_match_iterator< Storage >::operator-> ( ) const
inlineconstexpr

Returns pointer to the current match.

Definition at line 313 of file real.hpp.

◆ operator==()

template<typename Storage >
constexpr bool real::basic_match_iterator< Storage >::operator== ( const basic_match_iterator< Storage > &  other) const
inlineconstexpr

Returns true if both denote the same position/end.

Parameters
[in]otherAnother iterator.
Returns
true if both denote the same position/end.

Definition at line 344 of file real.hpp.

Member Data Documentation

◆ cascade_

template<typename Storage >
bool real::basic_match_iterator< Storage >::cascade_ {}
private

OPT-C: chosen once — run the memchr-cascade class-run variant for this whole walk.

Definition at line 357 of file real.hpp.

◆ current_

template<typename Storage >
value_type real::basic_match_iterator< Storage >::current_
private

The current match.

Definition at line 359 of file real.hpp.

◆ done_

template<typename Storage >
bool real::basic_match_iterator< Storage >::done_ {true}
private

True once exhausted.

Definition at line 356 of file real.hpp.

◆ forbid_empty_until_

template<typename Storage >
std::size_t real::basic_match_iterator< Storage >::forbid_empty_until_ {}
private

Empty-match guard (see pike.hpp).

Definition at line 355 of file real.hpp.

◆ pattern_

template<typename Storage >
std::string_view real::basic_match_iterator< Storage >::pattern_
private

Pattern text (named lookups).

Definition at line 352 of file real.hpp.

◆ pos_

template<typename Storage >
std::size_t real::basic_match_iterator< Storage >::pos_ {}
private

Current scan offset.

Definition at line 354 of file real.hpp.

◆ prog_

template<typename Storage >
detail::program_view real::basic_match_iterator< Storage >::prog_
private

The program being run.

Definition at line 351 of file real.hpp.

◆ sem_

template<typename Storage >
match_semantics real::basic_match_iterator< Storage >::sem_ {match_semantics::first}
private

leftmost-first (default) or longest (find_iter_longest).

Definition at line 358 of file real.hpp.

◆ state_

template<typename Storage >
Storage::state_type real::basic_match_iterator< Storage >::state_
private

VM scratch, reused across the walk.

Definition at line 360 of file real.hpp.

◆ text_

template<typename Storage >
std::string_view real::basic_match_iterator< Storage >::text_
private

The text being scanned.

Definition at line 353 of file real.hpp.


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