diff --git a/uppsrc/plugin/pcre/RegExp.cpp b/uppsrc/plugin/pcre/RegExp.cpp index 3a23d7503..d1c7ab348 100644 --- a/uppsrc/plugin/pcre/RegExp.cpp +++ b/uppsrc/plugin/pcre/RegExp.cpp @@ -30,11 +30,14 @@ RegExp::~RegExp() void RegExp::Clear(bool freemem) { + if(freemem && study) + pcre_free(study); if(freemem && cpattern) pcre_free(cpattern); first = false; cpattern = NULL; + study = NULL; rc = 0; compile_options = 0; execute_options = 0; @@ -70,9 +73,25 @@ bool RegExp::Compile(bool recompile) return error_code == 0; } +bool RegExp::Study(bool restudy) +{ + if(!cpattern) + Compile(); + if(study){ + if(restudy) + pcre_free(study); + else + return true; + } + study = pcre_study(cpattern, 0, &error_string); + if(error_string != NULL) + error_code = -1; // unfortunatelly, pcre_study doesn't return error codes... + return error_code == 0; +} + int RegExp::Execute(const String &t, int offset) { - rc = pcre_exec(cpattern, NULL, t, t.GetLength(), offset, execute_options, pos, 30); + rc = pcre_exec(cpattern, study, t, t.GetLength(), offset, execute_options, pos, 30); if(rc <= 0) first = false; return rc; diff --git a/uppsrc/plugin/pcre/RegExp.h b/uppsrc/plugin/pcre/RegExp.h index 1ac894098..bd9f84631 100644 --- a/uppsrc/plugin/pcre/RegExp.h +++ b/uppsrc/plugin/pcre/RegExp.h @@ -60,6 +60,7 @@ private: String pattern; String text; pcre * cpattern; + pcre_extra * study; const char * error_string; int error_offset; int error_code; @@ -75,6 +76,7 @@ public: void SetPattern(const char * p); void SetPattern(const String &p); bool Compile(bool recompile = false); + bool Study(bool restudy = false); int Execute(const String &t, int offset = 0); bool Match(const String &t, bool copy = true); bool FastMatch(const String &t); @@ -84,6 +86,7 @@ public: String GetString(int i); void GetMatchPos(int i, int& iPosStart, int& iPosAfterEnd); Vector GetStrings(); + String GetPattern() const { return pattern; } bool IsError() { return error_code != 0; }