Esempio n. 1
0
        internal int DrainRemainingDataForGetByteCount()
        {
            int totalByteCount = 0;

            Rune thisRune;

            while ((thisRune = GetNextRune()).Value != 0)
            {
                if (!encoding.TryGetByteCount(thisRune, out int byteCountThisIteration))
                {
                    // We can't fallback the fallback. We can't make forward progress, so report to our caller
                    // that something went terribly wrong. The error message contains the fallback char that
                    // couldn't be converted. (Ideally we'd provide the first char that originally triggered
                    // the fallback, but it's complicated to keep this state around, and a fallback producing
                    // invalid data should be a very rare occurrence.)

                    ThrowLastCharRecursive(thisRune.Value);
                }

                Debug.Assert(byteCountThisIteration >= 0, "Encoding shouldn't have returned a negative byte count.");

                // We need to check for overflow while tallying the fallback byte count.

                totalByteCount += byteCountThisIteration;
                if (totalByteCount < 0)
                {
                    InternalReset();
                    Encoding.ThrowConversionOverflow();
                }
            }

            return(totalByteCount);
        }