Exemplo n.º 1
0
 public virtual SyntaxHighlightSegmentList FindAllSegments(string text, bool cached)
 {
     if (AllSegments == null || !cached)
     {
         AllSegments = FindAllSegments(text);
     }
     return(AllSegments);
 }
Exemplo n.º 2
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 another segments in the same list
        /// </summary>
        public virtual void RemoveOverlappingSegments()
        {
            SyntaxHighlightSegmentList res = new SyntaxHighlightSegmentList();

            res.AddRange(this);
            for (int i = res.Count - 1; i >= 0; i--)
            {
                for (int j = 0; j < i; j++)
                {
                    if (this[j].SuperiorTo(res[i]))
                    {
                        res.RemoveAt(i);
                        break;
                    }
                }
            }
            this.Clear();
            this.AddRange(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);
        }