Пример #1
0
        public virtual SyntaxHighlightSegmentList FindAllSegments(string text)
        {
            SyntaxHighlightSegmentList res = new SyntaxHighlightSegmentList();

            foreach (string def in Definition)
            {
                Regex           regex   = new Regex(def, Options);
                MatchCollection matches = regex.Matches(text);
                foreach (Match match in matches)
                {
                    res.Add(new SyntaxHighlightSegment(match.Index, match.Index + match.Length));
                }
            }
            res.RemoveOverlappingSegments();
            return(res);
        }
        /// <summary>
        /// Remove segments from this list that are overlapped by those in masterList
        /// </summary>
        /// <param name="masterList"></param>
        public virtual void RemoveOverlappingSegments(SyntaxHighlightSegmentList masterList)
        {
            SyntaxHighlightSegmentList res = new SyntaxHighlightSegmentList();

            foreach (SyntaxHighlightSegment thisSegment in this)
            {
                bool doAdd = true;
                foreach (SyntaxHighlightSegment masterSegment in masterList)
                {
                    if (masterSegment.SuperiorTo(thisSegment))
                    {
                        doAdd = false;
                        break;
                    }
                }
                if (doAdd)
                {
                    res.Add(thisSegment);
                }
            }
            this.Clear();
            this.AddRange(res);
        }