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

208 {
209 if (groupId < m_subMatches.size())
210 {
211 if (index>=m_subMatches[groupId].position())
212 {
213 m_subMatches[groupId].setEnd(index);
214 }
215 }
216 }
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:223

References m_subMatches, and position().

◆ init()

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

Definition at line 190 of file regex.h.

191 {
192 m_subMatches.clear();
193 m_subMatches.reserve(captureCount+1);
194 for (size_t i=0;i<captureCount+1;i++)
195 {
196 m_subMatches.emplace_back(str);
197 }
198 m_str = str;
199 }
std::string_view m_str
Definition regex.h:224
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::Ex::Private::matchAt(), and suffix().

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

186{ 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::Ex::Private::matchAt(), prefix(), and suffix().

◆ 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().

◆ setMatch()

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

Definition at line 217 of file regex.h.

218 {
219 // Always set the whole match
220 m_subMatches[0].setMatch(pos,len);
221 }

References m_subMatches.

◆ size()

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

Returns the number of sub matches available in this match.

Definition at line 181 of file regex.h.

181{ return m_subMatches.size(); }

References m_subMatches.

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

◆ startCapture()

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

Definition at line 200 of file regex.h.

201 {
202 if (groupId < m_subMatches.size())
203 {
204 m_subMatches[groupId].setStart(index);
205 }
206 }

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().

◆ Ex

friend class Ex
friend

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

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

◆ m_subMatches

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

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