SlHelpers
SlPCRE2::PCRE2 Class Reference

Perl-compatible regex. More...

#include <PCRE2.h>

Public Member Functions

 PCRE2 () noexcept
 Constructs an empty PCRE2.
 
 PCRE2 (const PCRE2 &)=delete
 
PCRE2operator= (const PCRE2 &)=delete
 
 PCRE2 (PCRE2 &&other) noexcept
 Move constructor.
 
PCRE2operator= (PCRE2 &&other) noexcept
 Move assignment.
 
bool compile (std::string_view regex, uint32_t options=0) noexcept
 Compile PCRE2 regex with passed options. More...
 
int match (std::string_view subject) noexcept
 PCRE2 against subject. More...
 
auto ovector () const
 Returns offset (into the subject string) vector for all matches. More...
 
auto matches (std::string_view subject, unsigned matches) const noexcept
 Returns Matches (a pseudo-vector of matches) in subject. More...
 
auto matchByIdx (std::string_view subject, unsigned index) const noexcept
 Returns one match – a substring of subject. More...
 
auto lastErrno () const noexcept
 Return the last error number.
 
auto lastError () const noexcept
 Return the last error string if any.
 
auto lastOffset () const noexcept
 Get offset of last error (to the regex string)
 
bool valid () const noexcept
 Test whether PCRE2 is valid.
 
 operator bool () const noexcept
 bool wrapper around valid()
 
bool operator! () const noexcept
 ! wrapper around valid()
 

Static Public Member Functions

static std::string errToStr (int err)
 Converts PCRE2 error code err to string. More...
 

Detailed Description

Perl-compatible regex.

Member Function Documentation

◆ compile()

bool SlPCRE2::PCRE2::compile ( std::string_view  regex,
uint32_t  options = 0 
)
inlinenoexcept

Compile PCRE2 regex with passed options.

Parameters
regexRegex to compile
optionsOptions to use (like PCRE2_CASELESS)
Returns
true on success

◆ errToStr()

static std::string SlPCRE2::PCRE2::errToStr ( int  err)
inlinestatic

Converts PCRE2 error code err to string.

Parameters
errPCRE2 error code
Returns
Error string.

◆ match()

int SlPCRE2::PCRE2::match ( std::string_view  subject)
inlinenoexcept

PCRE2 against subject.

Parameters
subjectText to match the regex to
Returns
negative on error, 1 for no match, 2 for one group matched, ...

◆ matchByIdx()

auto SlPCRE2::PCRE2::matchByIdx ( std::string_view  subject,
unsigned  index 
) const
inlinenoexcept

Returns one match – a substring of subject.

Parameters
subjectSubject matched
indexIndex of the requested match
Returns
Matched string.

◆ matches()

auto SlPCRE2::PCRE2::matches ( std::string_view  subject,
unsigned  matches 
) const
inlinenoexcept

Returns Matches (a pseudo-vector of matches) in subject.

Parameters
subjectSubject matched
matchesNumber of matches – the return value of match()
Returns
Pseudo-vector of matches.

◆ ovector()

auto SlPCRE2::PCRE2::ovector ( ) const
inline

Returns offset (into the subject string) vector for all matches.

Returns
An array of size_t values.

Preferrably, use matches() or matchByIdx() wrappers.


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