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 SubMatch & operator[] (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< SubMatch > m_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 159 of file regex.h.

Constructor & Destructor Documentation

◆ Match()

reg::Match::Match ( )
inline

Creates an empty match object.

Definition at line 163 of file regex.h.

163{}

Member Function Documentation

◆ endCapture()

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

Definition at line 222 of file regex.h.

223 {
224 if (groupId < m_subMatches.size())
225 {
226 if (index>=m_subMatches[groupId].position())
227 {
228 m_subMatches[groupId].setEnd(index);
229 }
230 }
231 }
size_t position() const
Returns the position of the match or std::string::npos if no position is set.
Definition regex.h:166
std::vector< SubMatch > m_subMatches
Definition regex.h:238

References m_subMatches, and position().

◆ init()

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

Definition at line 205 of file regex.h.

206 {
207 m_subMatches.clear();
208 m_subMatches.reserve(captureCount+1);
209 for (size_t i=0;i<captureCount+1;i++)
210 {
211 m_subMatches.emplace_back(str);
212 }
213 m_str = str;
214 }
std::string_view m_str
Definition regex.h:239
std::string str() const
Return a string representing the matching part.
Definition regex.h:172

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

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

References m_subMatches.

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

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

201{ 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 166 of file regex.h.

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

References m_subMatches.

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

◆ prefix()

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

Return the part of the string before the match.

Definition at line 175 of file regex.h.

175{ 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 232 of file regex.h.

233 {
234 // Always set the whole match
235 m_subMatches[0].setMatch(pos,len);
236 }

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

192 {
193 size_t s = m_subMatches.size();
194 while (s > 1 && m_subMatches[s-1].position() == std::string::npos) s--;
195 return s;
196 }

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

216 {
217 if (groupId < m_subMatches.size())
218 {
219 m_subMatches[groupId].setStart(index);
220 }
221 }

References m_subMatches.

◆ str()

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

Return a string representing the matching part.

Definition at line 172 of file regex.h.

172{ 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 178 of file regex.h.

179 {
180 SubMatch m(m_str);
181 if (!m_str.empty())
182 {
183 size_t e = position()+length();
184 m.setMatch(e,m_str.length()-e);
185 }
186 return m;
187 }
size_t length() const
Returns the position of the match or std::string::npos if no length is set.
Definition regex.h:169

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

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

◆ Ex

friend class Ex
friend

Definition at line 204 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 239 of file regex.h.

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

◆ m_subMatches

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

Definition at line 238 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: