﻿// Decompiled with JetBrains decompiler
// Type: System.Xml.IncrementalReadCharsDecoder
// Assembly: System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 50ABAB51-7DC3-4F0A-A797-0D0C2D124D60
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Xml.dll

using System;
using System.Runtime;

namespace System.Xml
{
  internal class IncrementalReadCharsDecoder : IncrementalReadDecoder
  {
    private char[] buffer;
    private int startIndex;
    private int curIndex;
    private int endIndex;

    internal override int DecodedCount
    {
      get
      {
        return this.curIndex - this.startIndex;
      }
    }

    internal override bool IsFull
    {
      get
      {
        return this.curIndex == this.endIndex;
      }
    }

    [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
    internal IncrementalReadCharsDecoder()
    {
    }

    internal override int Decode(char[] chars, int startPos, int len)
    {
      int num = this.endIndex - this.curIndex;
      if (num > len)
        num = len;
      Buffer.BlockCopy((Array) chars, startPos * 2, (Array) this.buffer, this.curIndex * 2, num * 2);
      this.curIndex += num;
      return num;
    }

    internal override int Decode(string str, int startPos, int len)
    {
      int count = this.endIndex - this.curIndex;
      if (count > len)
        count = len;
      str.CopyTo(startPos, this.buffer, this.curIndex, count);
      this.curIndex += count;
      return count;
    }

    internal override void Reset()
    {
    }

    internal override void SetNextOutputBuffer(Array buffer, int index, int count)
    {
      this.buffer = (char[]) buffer;
      this.startIndex = index;
      this.curIndex = index;
      this.endIndex = index + count;
    }
  }
}
