コード例 #1
0
 public Buffer(Stream codeStream, Encoding encoding)
 {
     CodeStreamReader = new StreamReader(codeStream, encoding, true);
     FillPendingBuffer();
     BufferStr = PendingBufferStr;
     FillPendingBuffer();
     HeadStr   = BufferStr.Substring(0, Math.Min(HeadStringSize, BufferStr.Length));
     BufferStr = BufferStr.Substring(HeadStr.Length);
 }
コード例 #2
0
        public int Pop(int count)
        {
#if DEBUG
            if (HeadStr.Length > HeadStringSize)
            {
                throw new Exception("wtf?!");
            }
#endif

            if (count > HeadStringSize || count < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(count), "count must be between 1 and 100");
            }

            var      poped = Math.Min(HeadStr.Length, count);
            string   popedValue;
            string[] lines;

            if (poped < count)
            {
                popedValue = HeadStr.Substring(0, poped);

                HeadStr = "";

                lines  = popedValue.Split('\n');
                Line  += lines.Length - 1;
                Column = lines.Length > 1 ? lines.Last().Length + 1 : Column + poped;

                return(poped);
            }

            if (BufferStr.Length < poped)
            {
                BufferStr       += PendingBufferStr;
                PendingBufferStr = "";
                FillPendingBuffer();
            }
            if (BufferStr.Length < poped)
            {
                HeadStr  += BufferStr;
                BufferStr = "";

                popedValue = HeadStr.Substring(0, poped);

                HeadStr = HeadStr.Substring(poped);

                lines  = popedValue.Split('\n');
                Line  += lines.Length - 1;
                Column = lines.Length > 1 ? lines.Last().Length + 1 : Column + poped;

                return(poped);
            }

            HeadStr += BufferStr.Substring(0, poped);

            popedValue = HeadStr.Substring(0, poped);

            HeadStr   = HeadStr.Substring(poped);
            BufferStr = BufferStr.Substring(poped);

            lines  = popedValue.Split('\n');
            Line  += lines.Length - 1;
            Column = lines.Length > 1 ? lines.Last().Length + 1 : Column + poped;

            return(poped);
        }