コード例 #1
0
        public void Process(string code)
        {
            string[] lines = code.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
            backing_ = new ScanDepth[lines.Length];

            int depth = 0;

            for (int i = 0; i < lines.Length; ++i)
            {
                backing_[i] = new ScanDepth();
                backing_[i].PushDepth(0, depth); //Push start of line depth

                for (int c = 0; c < lines[i].Length; ++c)
                {
                    char charCode = lines[i][c];
                    if (charCode == '{')
                    {
                        ++depth;
                        backing_[i].PushDepth(c, depth);
                    }
                    else if (charCode == '}')
                    {
                        --depth;
                        backing_[i].PushDepth(c, depth);
                    }
                }
            }
        }
コード例 #2
0
        public void Process(string code)
        {
            string[] lines = code.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
            backing_ = new ScanDepth[lines.Length];

            int depth = 0;
            for (int i = 0; i < lines.Length; ++i) {
                backing_[i] = new ScanDepth();
                backing_[i].PushDepth(0, depth); //Push start of line depth

                for (int c = 0; c < lines[i].Length; ++c)
                {
                    char charCode = lines[i][c];
                    if (charCode == '{')
                    {
                        ++depth;
                        backing_[i].PushDepth(c, depth);
                    } else if (charCode == '}')
                    {
                        --depth;
                        backing_[i].PushDepth(c, depth);
                    }
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// More accurate depth at a specific character position in a line
 /// </summary>
 /// <param name="aLine"></param>
 /// <param name="aIndex"></param>
 /// <returns></returns>
 public int GetBraceDepth(int aLine, int aIndex)
 {
     if (aLine >= 0 && aLine < backing_.Length)
     {
         ScanDepth d = backing_[aLine];
         for (int i = 0; i < d.Positions.Length; ++i)
         {
             if (d.Positions[i] >= aIndex)
             {
                 if (i > 0)
                 {
                     return(d.Positions[i - 1]);
                 }
                 return(d.Positions[0]);
             }
         }
     }
     return(-1);
 }