Skip to main content

The Iterator Class Reference

Class to iterate through matches. More...

Declaration

class reg::Iterator { ... }

Included Headers

#include <src/regex.h>

Public Member Typedefs Index

usingvalue_type = Match
usingdifference_type = std::ptrdiff_t
usingpointer = value_type *
usingreference = value_type &
usingiterator_category = std::forward_iterator_tag

Public Constructors Index

Iterator ()

Creates an end-of-sequence iterator. More...

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. More...

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

Public Operators Index

booloperator== (const Iterator &rhs) const

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

booloperator!= (const Iterator &rhs) const

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

const value_type &operator* () const

Returns a reference to the current match. More...

const value_type *operator-> () const

Returns a pointer to the current match. More...

Iterator &operator++ ()

Advances the iterator to the next match. More...

Private Member Functions Index

voidfindNext ()

Private Member Attributes Index

std::string_viewm_str
const Ex *m_re = nullptr
size_tm_pos = std::string::npos
Matchm_match

Description

Class to iterate through matches.

Definition at line 231 of file regex.h.

Public Member Typedefs

difference_type

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

Definition at line 235 of file regex.h.

235 using difference_type = std::ptrdiff_t;

iterator_category

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

Definition at line 238 of file regex.h.

238 using iterator_category = std::forward_iterator_tag;

pointer

using reg::Iterator::pointer = value_type*

Definition at line 236 of file regex.h.

reference

using reg::Iterator::reference = value_type&

Definition at line 237 of file regex.h.

value_type

using reg::Iterator::value_type = Match

Definition at line 234 of file regex.h.

Public Constructors

Iterator()

reg::Iterator::Iterator ()
inline

Creates an end-of-sequence iterator.

Definition at line 241 of file regex.h.

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

Iterator()

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.

info

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

Definition at line 246 of file regex.h.

246 Iterator(std::string_view str, const Ex &re, size_t pos=0)
247 : m_str(str), m_re(&re), m_pos(pos) { findNext(); }

References findNext, m_pos, m_re and m_str.

Iterator()

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

Definition at line 251 of file regex.h.

Iterator()

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

Definition at line 252 of file regex.h.

Iterator()

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

Definition at line 253 of file regex.h.

Public Operators

operator->()

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

Returns a pointer to the current match.

Definition at line 265 of file regex.h.

265 const value_type *operator->() const { return &m_match; }

Reference m_match.

operator!=()

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

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

Definition at line 259 of file regex.h.

259 bool operator!=(const Iterator &rhs) const { return rhs.m_pos!=m_pos; }

References Iterator and m_pos.

operator*()

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

Returns a reference to the current match.

Definition at line 262 of file regex.h.

262 const value_type &operator*() const { return m_match; }

Reference m_match.

operator++()

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

Advances the iterator to the next match.

Definition at line 268 of file regex.h.

268 Iterator &operator++() { findNext(); return *this; }

References findNext and Iterator.

operator==()

bool reg::Iterator::operator== (const Iterator & rhs)
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 bool operator==(const Iterator &rhs) const { return rhs.m_pos==m_pos; }

References Iterator and m_pos.

Private Member Functions

findNext()

void reg::Iterator::findNext ()
inline

Definition at line 271 of file regex.h.

271 void findNext()
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 }

References m_match, m_pos, m_re and m_str.

Referenced by Iterator and operator++.

Private Member Attributes

m_match

Match reg::Iterator::m_match

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

Definition at line 285 of file regex.h.

285 size_t m_pos = std::string::npos;

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

m_re

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

Definition at line 284 of file regex.h.

284 const Ex *m_re = nullptr;

Referenced by findNext and Iterator.

m_str

std::string_view reg::Iterator::m_str

Definition at line 283 of file regex.h.

283 std::string_view m_str;

Referenced by findNext and Iterator.


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


Generated via doxygen2docusaurus by Doxygen 1.14.0.