Пример #1
0
 public void Parse(string sName, string sInputLine)
 {
     Name = sName;
     items = new List<MessageItem>();
     if (string.IsNullOrEmpty(sInputLine))
         return;
     sLines = sInputLine.Split("\r\n".ToCharArray());
     MessageItem cur = null;
     int iLevel = -1;
     foreach (string el in sLines)
     {
         string sLine = el.Trim();
         if (string.IsNullOrEmpty(sLine))
             continue;
         MessageItem item = new MessageItem();
         item.Parse(sLine);
         if (string.IsNullOrEmpty(item.sName))
             continue;
         item.parent = cur;
         if (cur == null)
             items.Add(item);
         else
             cur.childs.Add(item);
         if (!string.IsNullOrEmpty(item.sTail))
         {
             int iCount = item.sTail.Count(c => c == '+');
             if (iCount != 0)
             {
                 for (int i = item.sTail.Length - 1; i >= 0; i--)
                 {
                     if (item.sTail[i] == '+')
                     {
                         if (iLevel < i)
                         {
                             iLevel = i;
                             cur = item;
                             break;
                         }
                         if (iLevel == i)
                         {
                             cur = cur.parent;
                             iLevel--;
                             continue;
                         }
                     }
                 }
             }
         }
     }
 }
Пример #2
0
 public void Parse(string sInputLine)
 {
     childs = new List<MessageItem>();
     parent = null;
     Line = sInputLine;
     string sLine = Line.Trim();
     if (string.IsNullOrEmpty(sLine))
         return;
     int iPos = sLine.IndexOf(" ");
     if (iPos == -1)
         return;
     sPos = sLine.Substring(0, iPos).Trim();
     sLine = sLine.Substring(iPos).Trim();
     if (sLine[1] == ' ')
         sLine = sLine.Substring(2);
     if (sLine[0] != '-')
     {
         sTag = sLine.Substring(0, 3).Trim();
         sLine = sLine.Substring(3).Trim();
     }
     iPos = sLine.LastIndexOfAny("0123456789".ToCharArray());
     if (iPos == -1)
     {
         return;
     }
     int iPos2 = sLine.LastIndexOfAny("CM".ToCharArray(), iPos);
     if (iPos2 == -1)
     {
         return;
     }
     sS = sLine.Substring(iPos2, 1).Trim();
     string sBuf = sLine.Substring(iPos2 + 1, iPos - iPos2).Trim();
     sTail = sLine.Substring(iPos + 1).Trim();
     sTail = new string(sTail.ToCharArray().Reverse().ToArray());
     int.TryParse(sBuf, out iR);
     sName = sLine.Substring(0, iPos2).Trim();
 }