pcre.diff

Jan DolinĂ¡r, 07/04/2012 07:39 PM

Download (2.07 KB)

View differences:

uppsrc/plugin/pcre/RegExp.cpp (working copy)
30 30

  
31 31
void RegExp::Clear(bool freemem)
32 32
{
33
	if(freemem && study)
34
		pcre_free(study);
33 35
	if(freemem && cpattern)
34 36
		pcre_free(cpattern);
35 37

  
36 38
	first = false;
37 39
	cpattern = NULL;
40
	study = NULL;
38 41
	rc = 0;
39 42
	compile_options = 0;
40 43
	execute_options = 0;
......
70 73
	return error_code == 0;
71 74
}
72 75

  
76
bool RegExp::Study(bool restudy)
77
{
78
	if(!cpattern)
79
		Compile();
80
	if(study){
81
		if(restudy)
82
			pcre_free(study);
83
		else
84
			return true;
85
	}
86
	study = pcre_study(cpattern, 0, &error_string);
87
	if(error_string != NULL)
88
		error_code = -1; // unfortunatelly, pcre_study doesn't return error codes...
89
	return error_code == 0;
90
}
91

  
73 92
int RegExp::Execute(const String &t, int offset)
74 93
{
75
	rc = pcre_exec(cpattern, NULL, t, t.GetLength(), offset, execute_options, pos, 30);
94
	rc = pcre_exec(cpattern, study, t, t.GetLength(), offset, execute_options, pos, 30);
76 95
	if(rc <= 0)
77 96
		first = false;
78 97
	return rc;
uppsrc/plugin/pcre/RegExp.h (working copy)
60 60
	String pattern;
61 61
	String text;
62 62
	pcre * cpattern;
63
	pcre_extra * study;
63 64
	const char * error_string;
64 65
	int error_offset;
65 66
	int error_code;
......
75 76
	void           SetPattern(const char * p);
76 77
	void           SetPattern(const String &p);
77 78
	bool           Compile(bool recompile = false);
79
	bool           Study(bool restudy = false);
78 80
	int            Execute(const String &t, int offset = 0);
79 81
	bool           Match(const String &t, bool copy = true);
80 82
	bool           FastMatch(const String &t);
......
84 86
	String         GetString(int i);
85 87
	void           GetMatchPos(int i, int& iPosStart, int& iPosAfterEnd);
86 88
	Vector<String> GetStrings();
89
	String         GetPattern() const { return pattern; }
87 90

  
88 91

  
89 92
	bool           IsError() { return error_code != 0; }