Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
regex.cpp: moved pcreErrorCodeToString() into PcreRegex
  • Loading branch information
firewave committed Apr 7, 2026
commit 6c3e75eb80118fae5ad9f94008441852bf2f6824
60 changes: 31 additions & 29 deletions lib/regex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,37 @@
#include <pcre.h>

namespace {
std::string pcreErrorCodeToString(const int pcreExecRet)
class PcreRegex : public Regex
{
public:
explicit PcreRegex(std::string pattern)
: mPattern(std::move(pattern))
{}

~PcreRegex() override
{
if (mExtra) {
pcre_free_study(mExtra);
mExtra = nullptr;
}
if (mRe) {
pcre_free(mRe);
mRe = nullptr;
}
}

std::string compile();
std::string match(const std::string& str, const MatchFn& match) const override;

private:
static std::string pcreErrorCodeToString(int pcreExecRet);

std::string mPattern;
pcre* mRe{};
pcre_extra* mExtra{};
};

std::string PcreRegex::pcreErrorCodeToString(const int pcreExecRet)
{
switch (pcreExecRet) {
case PCRE_ERROR_NULL:
Expand Down Expand Up @@ -157,34 +187,6 @@ namespace {
return "unknown PCRE error " + std::to_string(pcreExecRet);
}

class PcreRegex : public Regex
{
public:
explicit PcreRegex(std::string pattern)
: mPattern(std::move(pattern))
{}

~PcreRegex() override
{
if (mExtra) {
pcre_free_study(mExtra);
mExtra = nullptr;
}
if (mRe) {
pcre_free(mRe);
mRe = nullptr;
}
}

std::string compile();
std::string match(const std::string& str, const MatchFn& match) const override;

private:
std::string mPattern;
pcre* mRe{};
pcre_extra* mExtra{};
};

std::string PcreRegex::compile()
{
if (mRe)
Expand Down