Doxygen
Loading...
Searching...
No Matches
reg::Iterator Class Reference

Class to iterate through matches. More...

#include <src/regex.h>

Collaboration diagram for reg::Iterator:

Public Types

using value_type = Match
using difference_type = std::ptrdiff_t
using pointer = value_type*
using reference = value_type&
using iterator_category = std::forward_iterator_tag

Public Member Functions

 Iterator ()
 Creates an end-of-sequence iterator.
 Iterator (std::string_view str, const Ex &re, size_t pos=0)
 Creates an iterator for input string str, using regular expression re to search.
 Iterator (std::string &&str, const Ex &re)=delete
 Iterator (const std::string &str, Ex &&re)=delete
 Iterator (std::string &&str, Ex &&re)=delete
bool operator== (const Iterator &rhs) const
 Returns true if the iterators point to the same match (or both are end-of-sequence iterators).
bool operator!= (const Iterator &rhs) const
 Returns true if the iterators are not pointing to the same match.
const value_typeoperator* () const
 Returns a reference to the current match.
const value_typeoperator-> () const
 Returns a pointer to the current match.
Iteratoroperator++ ()
 Advances the iterator to the next match.

Private Member Functions

void findNext ()

Private Attributes

std::string_view m_str
const Exm_re = nullptr
size_t m_pos = std::string::npos
Match m_match

Detailed Description

Class to iterate through matches.

Definition at line 235 of file regex.h.

Member Typedef Documentation

◆ difference_type

using reg::Iterator::difference_type = std::ptrdiff_t

Definition at line 239 of file regex.h.

◆ iterator_category

using reg::Iterator::iterator_category = std::forward_iterator_tag

Definition at line 242 of file regex.h.

◆ pointer

Definition at line 240 of file regex.h.

◆ reference

Definition at line 241 of file regex.h.

◆ value_type

Definition at line 238 of file regex.h.

Constructor & Destructor Documentation

◆ Iterator() [1/5]

reg::Iterator::Iterator ( )
inline

Creates an end-of-sequence iterator.

Definition at line 245 of file regex.h.

245{}

Referenced by operator!=(), operator++(), and operator==().

◆ Iterator() [2/5]

reg::Iterator::Iterator ( std::string_view str,
const Ex & re,
size_t pos = 0 )
inline

Creates an iterator for input string str, using regular expression re to search.

Note
the string and regular expression objects should remain valid while iterating.

Definition at line 250 of file regex.h.

251 : m_str(str), m_re(&re), m_pos(pos) { findNext(); }
size_t m_pos
Definition regex.h:289
std::string_view m_str
Definition regex.h:287
const Ex * m_re
Definition regex.h:288
void findNext()
Definition regex.h:275

References findNext(), m_pos, m_re, and m_str.

◆ Iterator() [3/5]

reg::Iterator::Iterator ( std::string && str,
const Ex & re )
delete

◆ Iterator() [4/5]

reg::Iterator::Iterator ( const std::string & str,
Ex && re )
delete

◆ Iterator() [5/5]

reg::Iterator::Iterator ( std::string && str,
Ex && re )
delete

Member Function Documentation

◆ findNext()

void reg::Iterator::findNext ( )
inlineprivate

Definition at line 275 of file regex.h.

276 {
277 if (!m_re || m_str.empty()) { m_pos=std::string::npos; return; } // end marker
279 {
280 m_pos=m_match.position()+m_match.length(); // update m_pos to point beyond last match
281 }
282 else // no more matches, make the iterator point to the 'end-of-sequence'
283 {
284 m_pos=std::string::npos;
285 }
286 }
bool match(std::string_view str, Match &match, size_t pos=0) const
Check if a given string matches this regular expression.
Definition regex.cpp:805
Match m_match
Definition regex.h:290
size_t position() const
Returns the position of the match or std::string::npos if no position is set.
Definition regex.h:157
size_t length() const
Returns the position of the match or std::string::npos if no length is set.
Definition regex.h:160

References reg::Match::length(), m_match, m_pos, m_re, m_str, reg::Ex::match(), and reg::Match::position().

Referenced by Iterator(), and operator++().

◆ operator!=()

bool reg::Iterator::operator!= ( const Iterator & rhs) const
inline

Returns true if the iterators are not pointing to the same match.

Definition at line 263 of file regex.h.

263{ return rhs.m_pos!=m_pos; }

References Iterator(), and m_pos.

◆ operator*()

const value_type & reg::Iterator::operator* ( ) const
inline

Returns a reference to the current match.

Definition at line 266 of file regex.h.

266{ return m_match; }

References m_match.

◆ operator++()

Iterator & reg::Iterator::operator++ ( )
inline

Advances the iterator to the next match.

Definition at line 272 of file regex.h.

272{ findNext(); return *this; }

References findNext(), and Iterator().

◆ operator->()

const value_type * reg::Iterator::operator-> ( ) const
inline

Returns a pointer to the current match.

Definition at line 269 of file regex.h.

269{ return &m_match; }

References m_match.

◆ operator==()

bool reg::Iterator::operator== ( const Iterator & rhs) const
inline

Returns true if the iterators point to the same match (or both are end-of-sequence iterators).

Definition at line 260 of file regex.h.

260{ return rhs.m_pos==m_pos; }

References Iterator(), and m_pos.

Member Data Documentation

◆ m_match

Match reg::Iterator::m_match
private

Definition at line 290 of file regex.h.

Referenced by findNext(), operator*(), and operator->().

◆ m_pos

size_t reg::Iterator::m_pos = std::string::npos
private

Definition at line 289 of file regex.h.

Referenced by findNext(), Iterator(), operator!=(), and operator==().

◆ m_re

const Ex* reg::Iterator::m_re = nullptr
private

Definition at line 288 of file regex.h.

Referenced by findNext(), and Iterator().

◆ m_str

std::string_view reg::Iterator::m_str
private

Definition at line 287 of file regex.h.

Referenced by findNext(), and Iterator().


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