plugin/pcre: Study method

git-svn-id: svn://ultimatepp.org/upp/trunk@5135 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2012-07-06 10:58:12 +00:00
parent 22444a42a8
commit 3e9d1c7dc3
2 changed files with 23 additions and 1 deletions

View file

@ -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;

View file

@ -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<String> GetStrings();
String GetPattern() const { return pattern; }
bool IsError() { return error_code != 0; }