Example #1
0
bool cppPCRE::RegExMatches( const std::string& text, int options, int startOffset, std::string* error )
{
	// output useful debug info
	CHECK_MSG( IsValid(), false, _(COMPILE_REGEX_ERROR) );

	// store the options
	mExecOptions = options;

	/*
	 - implement later
	// returned value may be used to speed up match
	pcre_extra *regexExtra = pcre_study(mRegex,
										options, // options
										&error);
	*/

	/*
	// get full info
	int pcre_fullinfo(const pcre *code, const pcre_extra *extra,
	int what, void *where);
	int rc;
	size_t len;
	rc = pcre_fullinfo(mRegex, regexExtra, PCRE_INFO_CAPTURECOUNT, &len);

	*/

	// convert the std::string to a std::string (for use with PCRE)
	const char* subject = (char*)NULL;

#if wxUSE_UNICODE
		subject = string(text.mb_str(wxConvUTF8)).c_str();
#else
		subject = (const char*)text.c_str();
#endif

	/*
	int pcre_exec(const pcre *code, const pcre_extra *extra,
	const char *subject, int length, int startoffset,
	int options, int *ovector, int ovecsize);
	*/
	// execute the pattern matching mechanism (obtain match vector, etc)
	mMatchCount = pcre_exec(
	mRegex,             /* result of pcre_compile() */
	0,           /* we didn't study the pattern */
	subject,  /* the subject string */
	(int)text.length(),             /* the length of the subject string */
	startOffset,              /* start at offset ? in the subject */
	mExecOptions,              /* options */
	mVector,        /* vector of integers for substring information */
	mVectorCount);            /* number of elements (NOT size in bytes) */

	return (mVector[0] >= 0);
}