private int GetChars(int maxCharsCount)
{
Debug.Assert(_ps.stream != null && _ps.decoder != null && _ps.bytes != null);
Debug.Assert(maxCharsCount <= _ps.chars.Length - _ps.charsUsed - 1);
// determine the maximum number of bytes we can pass to the decoder
int bytesCount = _ps.bytesUsed - _ps.bytePos;
if (bytesCount == 0)
{
return 0;
}
int charsCount;
bool completed;
try
{
// decode chars
_ps.decoder.Convert(_ps.bytes, _ps.bytePos, bytesCount, _ps.chars, _ps.charsUsed, maxCharsCount, false, out bytesCount, out charsCount, out completed);
}
catch (ArgumentException)
{
InvalidCharRecovery(ref bytesCount, out charsCount);
}
// move pointers and return
_ps.bytePos += bytesCount;
_ps.charsUsed += charsCount;
Debug.Assert(maxCharsCount >= charsCount);
return charsCount;
}