private List<HighlightingRange> HighlightLine(string line) { var ranges = new List<HighlightingRange>(); if (_highlightingRules != null) { for (var i = 0; i < _highlightingRules.Length; ++i) { var matches = _highlightingRules[i].Pattern.Matches(line); foreach (Match m in matches) { var cnd = new HighlightingRange { Color = _highlightingRules[i].Color, Start = m.Groups[1].Index, Length = m.Groups[1].Length }; if (!Intersects(ranges, cnd)) { ranges.Add(cnd); } } } } ranges.Sort((a, b) => a.Start.CompareTo(b.Start)); return ranges; }
private bool Intersects(List<HighlightingRange> ranges, HighlightingRange r) { for (var i = 0; i < ranges.Count; ++i) { if (!(r.Start > ranges[i].Start + ranges[i].Length || r.Start + r.Length < ranges[i].Start)) return true; } return false; }