Esempio n. 1
0
        public List <MatchEx> RegMatchList(IBuffer buf)
        {
            RegMatchExDic.Clear();
            List <MatchEx> mlist = new List <MatchEx>();

            foreach (Regex reg in RegDic.Keys)
            {
                foreach (Match m in reg.Matches(buf.ToString()))
                {
                    StringInfo sinfo1 = new StringInfo(buf.ToString().Substring(0, m.Index));
                    StringInfo sinfo2 = new StringInfo(buf.ToString().Substring(m.Index, m.Length));

                    int sindex  = sinfo1.LengthInTextElements;
                    int slength = sinfo2.LengthInTextElements;

                    MatchEx mex = new MatchEx(sindex,
                                              slength,
                                              m.Success);
                    RegMatchExDic.Add(mex, RegDic[reg]);

                    mlist.Add(mex);
                }
            }
            mlist.Sort(new MatchExComparer());

            return(mlist);
        }
Esempio n. 2
0
        public void Parse(IBuffer buffer, List <AttributeInfo> attributeList)
        {
            if (buffer.Length < attributeList.Count)
            {
                attributeList.RemoveRange(buffer.Length, attributeList.Count - buffer.Length);
            }
            else if (buffer.Length > attributeList.Count)
            {
                int cnt = buffer.Length - attributeList.Count;
                for (int i = 0; i < cnt; i++)
                {
                    attributeList.Add(new AttributeInfo());
                }
            }
            List <MatchEx> mlist = this.RegMatchList(buffer);

            int strIndex = 0;

            for (int i = 0; i < mlist.Count; i++)
            {
                if (mlist[i].Success)
                {
                    MatchEx mm = mlist[i];
                    if (mm.Index < strIndex)
                    {
                        break;
                    }

                    Color     color = this.GetMatchInfo(mm).FontColor;
                    TokenType type  = this.GetMatchInfo(mm).type;

                    int ist     = mm.Index;
                    int notmlen = ist - strIndex;
                    SetToken(buffer, strIndex, ist, attributeList, Color.Black, TokenType.TXT);
                    SetToken(buffer, ist, ist + mm.Length, attributeList, color, type);
                    strIndex = mm.Index + mm.Length;
                }
            }

            if (strIndex > 0 && strIndex < buffer.Length)
            {
                int len = buffer.Length - strIndex;
                for (int i = strIndex; i < buffer.Length; i++)
                {
                    attributeList[i].len       = len;
                    attributeList[i].forecolor = Color.Black;
                    len--;
                }
            }
            else if (strIndex == 0)
            {
                SetToken(buffer, 0, buffer.Length, attributeList, Color.Black, TokenType.TXT);
            }
        }
Esempio n. 3
0
 public HighlightInfo GetMatchInfo(MatchEx m)
 {
     return(RegMatchExDic[m]);
 }