예제 #1
0
        static bool IsSameTextAsCurrentSnapshot(ITextSnapshot snapshot, string text)
        {
            if (snapshot.Length != text.Length)
            {
                return(false);
            }
            if (text.Length == 0)
            {
                return(true);
            }
            int mid = text.Length / 2;

            if (snapshot[mid] != text[mid])
            {
                return(false);
            }
            var buf    = new char[Math.Min(1024, text.Length)];
            int offset = 0;

            while (offset < text.Length)
            {
                int count = Math.Min(buf.Length, text.Length - offset);
                snapshot.CopyTo(offset, buf, 0, count);
                for (int i = 0, j = offset; i < count; i++, j++)
                {
                    if (buf[i] != text[j])
                    {
                        return(false);
                    }
                }
                offset += count;
            }
            return(true);
        }
예제 #2
0
 int NextChar()
 {
     if (bufferPos >= bufferLen)
     {
         int len = snapshotLength - snapshotPos;
         if (len == 0)
         {
             return(-1);
         }
         if (len > buffer.Length)
         {
             len = buffer.Length;
         }
         snapshot.CopyTo(snapshotPos, buffer, 0, len);
         bufferLen = len;
         bufferPos = 0;
     }
     snapshotPos++;
     return(buffer[bufferPos++]);
 }
예제 #3
0
        public override int Read(char[] buffer, int index, int count)
        {
            int length = End - _position;

            if (length > 0)
            {
                length = System.Math.Min(length, count);
                _snapshot.CopyTo(_position, buffer, index, length);
                _position += length;
            }
            return(length);
        }
예제 #4
0
 public override void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)
 {
     textSnapshot.CopyTo(sourceIndex, destination, destinationIndex, count);
 }