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

Object representing the matching results. More...

#include <src/regex.h>

Public Member Functions

 Match ()
 Creates an empty match object.
size_t position () const
 Returns the position of the match or std::string::npos if no position is set.
size_t length () const
 Returns the position of the match or std::string::npos if no length is set.
std::string str () const
 Return a string representing the matching part.
SubMatch prefix () const
 Return the part of the string before the match.
SubMatch suffix () const
 Return the part of the string after the match.
size_t size () const
 Returns the number of sub matches available in this match.
const SubMatchoperator[] (size_t index) const
 Returns the n-th SubMatch object.

Private Member Functions

void init (std::string_view str, size_t captureCount)
void startCapture (size_t groupId, size_t index)
void endCapture (size_t groupId, size_t index)
void setMatch (size_t pos, size_t len)

Private Attributes

std::vector< SubMatchm_subMatches
std::string_view m_str

Friends

class Ex

Detailed Description

Object representing the matching results.

It consists of an array of SubMatch objects. The first entry of the array represents the whole match, any next elements represent each of the capture ranges.

For example string @42 and expression @(\\d+) will have two Submatches, match[0] will point to the input string as a whole, and match[1] will point to the number 42 only.

Definition at line 150 of file regex.h.

Constructor & Destructor Documentation

◆ Match()

reg::Match::Match ( )
inline

Creates an empty match object.

Definition at line 154 of file regex.h.

154{}

Member Function Documentation

◆ endCapture()

void reg::Match::endCapture ( size_t groupId,
size_t index )
inlineprivate

Definition at line 213 of file regex.h.

214 {
215 if (groupId < m_subMatches.size())
216 {
217 if (index>=m_subMatches[groupId].position())
218 {
219 m_subMatches[groupId].setEnd(index);
220 }
221 }
222 }
size_t position() const
Returns the position of the match or std::string::npos if no position is set.
Definition regex.h:157
std::vector< SubMatch > m_subMatches
Definition regex.h:229

References m_subMatches, and position().

◆ init()

void reg::Match::init ( std::string_view str,
size_t captureCount )
inlineprivate

Definition at line 196 of file regex.h.

197 {
198 m_subMatches.clear();
199 m_subMatches.reserve(captureCount+1);
200 for (size_t i=0;i<captureCount+1;i++)
201 {
202 m_subMatches.emplace_back(str);
203 }
204 m_str = str;
205 }
std::string_view m_str
Definition regex.h:230
std::string str() const
Return a string representing the matching part.
Definition regex.h:163

References m_str, m_subMatches, and str().

Referenced by reg::Ex::Private::matchAt().

◆ length()

size_t reg::Match::length ( ) const
inline

Returns the position of the match or std::string::npos if no length is set.

Definition at line 160 of file regex.h.

160{ return m_subMatches[0].length(); }

References m_subMatches.

Referenced by addValidAliasToMap(), reg::Iterator::findNext(), reg::Ex::Private::matchAt(), suffix(), and MemberDefImpl::writeDeclaration().

◆ operator[]()

const SubMatch & reg::Match::operator[] ( size_t index) const
inline

Returns the n-th SubMatch object.

Note that there is always 1 SubMatch object representing the whole match.

Definition at line 192 of file regex.h.

192{ return m_subMatches[index]; }

References m_subMatches.

◆ position()

size_t reg::Match::position ( ) const
inline

Returns the position of the match or std::string::npos if no position is set.

Definition at line 157 of file regex.h.

157{ return m_subMatches[0].position(); }

References m_subMatches.

Referenced by addValidAliasToMap(), endCapture(), reg::Iterator::findNext(), reg::Ex::Private::matchAt(), prefix(), size(), suffix(), and MemberDefImpl::writeDeclaration().

◆ prefix()

SubMatch reg::Match::prefix ( ) const
inline

Return the part of the string before the match.

Definition at line 166 of file regex.h.

166{ SubMatch m(m_str); m.setMatch(0,position()); return m; }

References m_str, position(), and reg::SubMatch::setMatch().

Referenced by MemberDefImpl::displayDefinition(), and MemberDefImpl::writeDocumentation().

◆ setMatch()

void reg::Match::setMatch ( size_t pos,
size_t len )
inlineprivate

Definition at line 223 of file regex.h.

224 {
225 // Always set the whole match
226 m_subMatches[0].setMatch(pos,len);
227 }

References m_subMatches.

◆ size()

size_t reg::Match::size ( ) const
inline

Returns the number of sub matches available in this match.

Only counts groups that actually matched (trailing unmatched optional groups are excluded).

Definition at line 182 of file regex.h.

183 {
184 size_t s = m_subMatches.size();
185 while (s > 1 && m_subMatches[s-1].position() == std::string::npos) s--;
186 return s;
187 }

References m_subMatches, and position().

Referenced by addValidAliasToMap(), and reg::Ex::Private::matchAt().

◆ startCapture()

void reg::Match::startCapture ( size_t groupId,
size_t index )
inlineprivate

Definition at line 206 of file regex.h.

207 {
208 if (groupId < m_subMatches.size())
209 {
210 m_subMatches[groupId].setStart(index);
211 }
212 }

References m_subMatches.

◆ str()

std::string reg::Match::str ( ) const
inline

Return a string representing the matching part.

Definition at line 163 of file regex.h.

163{ return std::string{m_subMatches[0].str()}; }

References m_subMatches.

Referenced by addValidAliasToMap(), init(), and initPredefined().

◆ suffix()

SubMatch reg::Match::suffix ( ) const
inline

Return the part of the string after the match.

Definition at line 169 of file regex.h.

170 {
171 SubMatch m(m_str);
172 if (!m_str.empty())
173 {
174 size_t e = position()+length();
175 m.setMatch(e,m_str.length()-e);
176 }
177 return m;
178 }
size_t length() const
Returns the position of the match or std::string::npos if no length is set.
Definition regex.h:160

References length(), m_str, position(), and reg::SubMatch::setMatch().

Referenced by MemberDefImpl::displayDefinition(), and MemberDefImpl::writeDocumentation().

◆ Ex

friend class Ex
friend

Definition at line 195 of file regex.h.

References Ex.

Referenced by Ex.

Member Data Documentation

◆ m_str

std::string_view reg::Match::m_str
private

Definition at line 230 of file regex.h.

Referenced by init(), prefix(), and suffix().

◆ m_subMatches

std::vector<SubMatch> reg::Match::m_subMatches
private

Definition at line 229 of file regex.h.

Referenced by endCapture(), init(), length(), operator[](), position(), setMatch(), size(), startCapture(), and str().


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