All pastes #463017 Raw Edit

Miscellany

public cpp v1 · immutable
#463017 ·published 2007-04-28 18:16 UTC
rendered paste body
int Highlighter::_search(regex_t **comp_regex, const string& regex, gchar* str, int length, int start, RegExMatch* pMatch){	UT_return_val_if_fail(pMatch, -2);	int startpos = -1; /* no match */		if (!(*comp_regex))	{		(*comp_regex) = new regex_t();		// precompile our regular expression, and cache the results			if (regcomp(*comp_regex, regex.c_str(), REG_EXTENDED) != 0)		{			UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);			DELETEP(*comp_regex);			return -2; /* internal error */		}		// TODO: add the creation of a fastmap if possible	}		re_registers regs;	int p = re_search(*comp_regex, str, length, start, length, &regs);	if (p >= 0)	{		// UT_DEBUGMSG(("match at pos %d for regex: %s\n", p, regex.c_str()));		startpos = p;				// byte index		pMatch->byte_start = p;		pMatch->byte_end = regs.end[0];					// character index		pMatch->char_start = g_utf8_pointer_to_offset(str, str + p); 		pMatch->char_end = g_utf8_pointer_to_offset(str, str + regs.end[0]);					//UT_DEBUGMSG(("  start: %d, end: %d   growbuf: start: %d, end: %d\n", pMatch->byte_start, pMatch->byte_end, pMatch->char_start, pMatch->char_end));	}	//(*comp_regex) = NULL;		return startpos;}