mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
plugin/pcre: Study method
git-svn-id: svn://ultimatepp.org/upp/trunk@5135 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
22444a42a8
commit
3e9d1c7dc3
2 changed files with 23 additions and 1 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue