Exemple #1
0
void Styler_Syntax::DoStyle(StyleRun& sr, unsigned int offset, const auto_vector<stxmatch>& matches) {
	const unsigned int rstart =  sr.GetRunStart();
	const unsigned int rend = sr.GetRunEnd();
	const unsigned int styleStart = offset < rstart ? rstart - offset : 0;
	const stxmatch m(wxEmptyString, NULL, styleStart, 0, 0, 0, NULL);

	if (matches.empty()) return;

	auto_vector<stxmatch>::const_iterator p = lower_bound(matches.begin(), matches.end(), &m, stxmatch_start_less());
	if (p != matches.begin()) --p;

	for (; p != matches.end(); ++p) {
		const unsigned int mStart = (*p)->start+offset;
		const unsigned int mEnd   = (*p)->end+offset;

		if (mStart > rend) break;

		// Check for overlap
		if (mEnd > rstart && mStart < rend) {
			const unsigned int start = wxMax(rstart, mStart);
			const unsigned int end = wxMin(rend, mEnd);

			const style* st = (*p)->st;
			if (st) {
				if (st->foregroundcolor != wxNullColour) sr.SetForegroundColor(start, end, st->foregroundcolor);
				if (st->backgroundcolor != wxNullColour) {
					sr.SetBackgroundColor(start, end, st->backgroundcolor);
					if (mEnd > rend) sr.SetExtendBgColor(st->backgroundcolor);
				}
				if (st->fontflags != wxFONTFLAG_DEFAULT) sr.SetFontStyle(start, end, st->fontflags);
			}

			// Check if there are submatches
			if ((*p)->subMatch.get()) {
				 DoStyle(sr, (*p)->start+offset, (*p)->subMatch->matches);
			}
		}
	}
}