public override int GetChars( byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex ) {
// finish a character from the bytes that were cached last time
int i = lastBytesCount;
if ( lastBytesCount > 0 ) {
// copy remaining bytes into the cache
for ( ; lastBytesCount < 4 && byteCount > 0; lastBytesCount++ ) {
lastBytes[lastBytesCount] = bytes[byteIndex];
byteIndex++;
byteCount--;
}
// still not enough bytes -> return
if ( lastBytesCount < 4 ) {
return 0;
}
// decode 1 character from the byte cache
i = GetFullChars( lastBytes, 0 , 4, chars, charIndex );
Debug.Assert( i == 1 );
charIndex += i;
lastBytesCount = 0;
}
else {
i = 0;
}
// decode block of byte quadruplets
i = GetFullChars( bytes, byteIndex, byteCount, chars, charIndex ) + i;
// cache remaining bytes that does not make up a character
int bytesLeft = ( byteCount & 0x3 );
if ( bytesLeft >= 0 ) {
for( int j = 0; j < bytesLeft; j++ ) {
lastBytes[j] = bytes[byteIndex + byteCount - bytesLeft + j];
}
lastBytesCount = bytesLeft;
}
return i;
}