Skip to main content

The Match Class Reference

Object representing the matching results. More...

Declaration

class reg::Match { ... }

Included Headers

#include <src/regex.h>

Friends Index

classEx

Public Constructors Index

Match ()

Creates an empty match object. More...

Public Operators Index

const SubMatch &operator[] (size_t index) const

Returns the n-th SubMatch object. More...

Public Member Functions Index

size_tposition () const

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

size_tlength () const

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

std::stringstr () const

Return a string representing the matching part. More...

SubMatchprefix () const

Return the part of the string before the match. More...

SubMatchsuffix () const

Return the part of the string after the match. More...

size_tsize () const

Returns the number of sub matches available in this match. More...

Private Member Functions Index

voidinit (std::string_view str)
voidstartCapture (size_t index)
voidendCapture (size_t index)
voidsetMatch (size_t pos, size_t len)

Private Member Attributes Index

std::vector< SubMatch >m_subMatches
size_tm_captureIndex =0
std::string_viewm_str
boolm_insideCapture =false

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

Friends

Ex

friend class Ex

Definition at line 191 of file regex.h.

191 friend class Ex;

Reference Ex.

Referenced by Ex.

Public Constructors

Match()

reg::Match::Match ()
inline

Creates an empty match object.

Definition at line 156 of file regex.h.

156 Match() {}

Public Operators

operator[]()

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

Returns the n-th SubMatch object.

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

Definition at line 188 of file regex.h.

188 const SubMatch &operator[](size_t index) const { return m_subMatches[index]; }

Reference m_subMatches.

Public Member Functions

length()

size_t reg::Match::length ()
inline

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

Definition at line 162 of file regex.h.

162 size_t length() const { return m_subMatches[0].length(); }

Reference m_subMatches.

Referenced by reg::Ex::Private::matchAt and suffix.

position()

size_t reg::Match::position ()
inline

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

Definition at line 159 of file regex.h.

159 size_t position() const { return m_subMatches[0].position(); }

Reference m_subMatches.

Referenced by prefix and suffix.

prefix()

SubMatch reg::Match::prefix ()
inline

Return the part of the string before the match.

Definition at line 168 of file regex.h.

168 SubMatch prefix() const { SubMatch m(m_str); m.setMatch(0,position()); return m; }

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

size()

size_t reg::Match::size ()
inline

Returns the number of sub matches available in this match.

Definition at line 183 of file regex.h.

183 size_t size() const { return m_subMatches.size(); }

Reference m_subMatches.

str()

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

Return a string representing the matching part.

Definition at line 165 of file regex.h.

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

Reference m_subMatches.

Referenced by init and initPredefined.

suffix()

SubMatch reg::Match::suffix ()
inline

Return the part of the string after the match.

Definition at line 171 of file regex.h.

172 {
173 SubMatch m(m_str);
174 if (!m_str.empty())
175 {
176 size_t e = position()+length();
177 m.setMatch(e,m_str.length()-e);
178 }
179 return m;
180 }

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

Private Member Functions

endCapture()

void reg::Match::endCapture (size_t index)
inline

Definition at line 209 of file regex.h.

209 void endCapture(size_t index)
210 {
211 if (index>m_subMatches.back().position())
212 {
214 m_subMatches.back().setEnd(index);
215 m_insideCapture = false;
216 }
217 }

References m_captureIndex, m_insideCapture and m_subMatches.

init()

void reg::Match::init (std::string_view str)
inline

Definition at line 192 of file regex.h.

192 void init(std::string_view str)
193 {
194 m_subMatches.clear();
195 m_subMatches.emplace_back(str);
196 m_str = str;
197 }

References m_str, m_subMatches and str.

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

setMatch()

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

Definition at line 218 of file regex.h.

218 void setMatch(size_t pos,size_t len)
219 {
220 m_subMatches[m_captureIndex].setMatch(pos,len);
221 }

References m_captureIndex and m_subMatches.

startCapture()

void reg::Match::startCapture (size_t index)
inline

Definition at line 198 of file regex.h.

198 void startCapture(size_t index)
199 {
200 if (!m_insideCapture) // when backtracking we can re-entry the capture multiple times
201 // only update the index, example `\s*(x)`
202 {
204 m_subMatches.emplace_back(m_str);
205 m_insideCapture = true;
206 }
207 m_subMatches.back().setStart(index);
208 }

References m_captureIndex, m_insideCapture, m_str and m_subMatches.

Private Member Attributes

m_captureIndex

size_t reg::Match::m_captureIndex =0

Definition at line 224 of file regex.h.

Referenced by endCapture, setMatch and startCapture.

m_insideCapture

bool reg::Match::m_insideCapture =false

Definition at line 226 of file regex.h.

226 bool m_insideCapture=false;

Referenced by endCapture and startCapture.

m_str

std::string_view reg::Match::m_str

Definition at line 225 of file regex.h.

225 std::string_view m_str;

Referenced by init, prefix, startCapture and suffix.

m_subMatches

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

Definition at line 223 of file regex.h.

223 std::vector<SubMatch> m_subMatches;

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


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


Generated via doxygen2docusaurus by Doxygen 1.14.0.