File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2828#include < pcre.h>
2929
3030namespace {
31- std::string pcreErrorCodeToString (const int pcreExecRet)
31+ class PcreRegex : public Regex
32+ {
33+ public:
34+ explicit PcreRegex (std::string pattern)
35+ : mPattern(std::move(pattern))
36+ {}
37+
38+ ~PcreRegex () override
39+ {
40+ if (mExtra ) {
41+ pcre_free_study (mExtra );
42+ mExtra = nullptr ;
43+ }
44+ if (mRe ) {
45+ pcre_free (mRe );
46+ mRe = nullptr ;
47+ }
48+ }
49+
50+ std::string compile ();
51+ std::string match (const std::string& str, const MatchFn& match) const override ;
52+
53+ private:
54+ static std::string pcreErrorCodeToString (int pcreExecRet);
55+
56+ std::string mPattern ;
57+ pcre* mRe {};
58+ pcre_extra* mExtra {};
59+ };
60+
61+ std::string PcreRegex::pcreErrorCodeToString (const int pcreExecRet)
3262 {
3363 switch (pcreExecRet) {
3464 case PCRE_ERROR_NULL:
@@ -157,34 +187,6 @@ namespace {
157187 return " unknown PCRE error " + std::to_string (pcreExecRet);
158188 }
159189
160- class PcreRegex : public Regex
161- {
162- public:
163- explicit PcreRegex (std::string pattern)
164- : mPattern(std::move(pattern))
165- {}
166-
167- ~PcreRegex () override
168- {
169- if (mExtra ) {
170- pcre_free_study (mExtra );
171- mExtra = nullptr ;
172- }
173- if (mRe ) {
174- pcre_free (mRe );
175- mRe = nullptr ;
176- }
177- }
178-
179- std::string compile ();
180- std::string match (const std::string& str, const MatchFn& match) const override ;
181-
182- private:
183- std::string mPattern ;
184- pcre* mRe {};
185- pcre_extra* mExtra {};
186- };
187-
188190 std::string PcreRegex::compile ()
189191 {
190192 if (mRe )
You can’t perform that action at this time.
0 commit comments