Beispiel #1
0
        public void Reset(int position)
        {
            // if position is within already read character range then just use what we have
            int relative = position - _basis;

            if (relative >= 0 && relative <= _characterWindowCount)
            {
                _offset = relative;
            }
            else
            {
                // we need to reread text buffer
                int amountToRead = Math.Min(_text.Length, position + _characterWindow.Length) - position;
                amountToRead = Math.Max(amountToRead, 0);
                if (amountToRead > 0)
                {
                    _text.CopyTo(position, _characterWindow, 0, amountToRead);
                }

                _lexemeStart          = 0;
                _offset               = 0;
                _basis                = position;
                _characterWindowCount = amountToRead;
            }
        }
        private void FillBuffer()
        {
            int charsToRead = Math.Min(_charBuffer.Length, _source.Length - _sourceOffset);

            _source.CopyTo(_sourceOffset, _charBuffer, 0, charsToRead);
            _sourceOffset     += charsToRead;
            _bufferOffset      = 0;
            _bufferUnreadChars = charsToRead;
        }
        /// <summary>
        /// Implements equality comparison of the content of two different instances of <see cref="SourceText"/>.
        /// </summary>
        /// <param name="other"></param>
        protected virtual bool ContentEqualsImpl(SourceText other)
        {
            if (other == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            if (Length != other.Length)
            {
                return(false);
            }

            var buffer1 = s_charArrayPool.Allocate();
            var buffer2 = s_charArrayPool.Allocate();

            try
            {
                int position = 0;
                while (position < Length)
                {
                    int n = Math.Min(Length - position, buffer1.Length);
                    CopyTo(position, buffer1, 0, n);
                    other.CopyTo(position, buffer2, 0, n);
                    for (int i = 0; i < n; i++)
                    {
                        if (buffer1[i] != buffer2[i])
                        {
                            return(false);
                        }
                    }

                    position += n;
                }

                return(true);
            }
            finally
            {
                s_charArrayPool.Free(buffer2);
                s_charArrayPool.Free(buffer1);
            }
        }
 public override void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)
 {
     _newText.CopyTo(sourceIndex, destination, destinationIndex, count);
 }