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

Iterator class to iterator 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

Iterator class to iterator through matches.

Definition at line 231 of file regex.h.

Member Typedef Documentation

◆ difference_type

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

Definition at line 235 of file regex.h.

◆ iterator_category

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

Definition at line 238 of file regex.h.

◆ pointer

Definition at line 236 of file regex.h.

◆ reference

Definition at line 237 of file regex.h.

◆ value_type

Definition at line 234 of file regex.h.

Constructor & Destructor Documentation

◆ Iterator() [1/5]

reg::Iterator::Iterator ( )
inline

Creates an end-of-sequence iterator.

Definition at line 241 of file regex.h.

241{}

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 246 of file regex.h.

247 : m_str(str), m_re(&re), m_pos(pos) { findNext(); }
size_t m_pos
Definition regex.h:285
std::string_view m_str
Definition regex.h:283
const Ex * m_re
Definition regex.h:284
void findNext()
Definition regex.h:271

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 271 of file regex.h.

272 {
273 if (!m_re || m_str.empty()) { m_pos=std::string::npos; return; } // end marker
274 if (m_re->match(m_str,m_match,m_pos))
275 {
276 m_pos=m_match.position()+m_match.length(); // update m_pos to point beyond last match
277 }
278 else // no more matches, make the iterator point to the 'end-of-sequence'
279 {
280 m_pos=std::string::npos;
281 }
282 }
Match m_match
Definition regex.h:286

References m_match, m_pos, m_re, and m_str.

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 259 of file regex.h.

259{ 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 262 of file regex.h.

262{ return m_match; }

References m_match.

◆ operator++()

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

Advances the iterator to the next match.

Definition at line 268 of file regex.h.

268{ 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 265 of file regex.h.

265{ 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 256 of file regex.h.

256{ 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 286 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 285 of file regex.h.

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

◆ m_re

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

Definition at line 284 of file regex.h.

Referenced by findNext(), and Iterator().

◆ m_str

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

Definition at line 283 of file regex.h.

Referenced by findNext(), and Iterator().


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