System.Text.ISO2022Encoding.GetMaxCharCount C# (CSharp) Method

GetMaxCharCount() public method

public GetMaxCharCount ( int byteCount ) : int
byteCount int
return int
        public override int GetMaxCharCount(int byteCount)
        {
            if (byteCount < 0)
                throw new ArgumentOutOfRangeException(nameof(byteCount), SR.ArgumentOutOfRange_NeedNonNegNum);
            Contract.EndContractBlock();

            int perChar = 1;
            int extraDecoder = 1;

            switch (CodePage)
            {
                case 50220:
                case 50221:
                case 50222:
                case 50225:
                    perChar = 1;        // Worst case all ASCII
                    extraDecoder = 3;   // Could have left over 3 chars of 4 char escape sequence, that all become ?
                    break;
                case 52936:
                    perChar = 1;        // Worst case all ASCII
                    extraDecoder = 1;   // sequences are 2 chars, so if next one is illegal, then previous 1 could be ?
                    break;
            }

            // Figure out our length, perchar * char + whatever extra our decoder could do to us.
            long charCount = ((long)byteCount * perChar) + extraDecoder;

            // Just in case we have to fall back unknown ones.
            if (DecoderFallback.MaxCharCount > 1)
                charCount *= DecoderFallback.MaxCharCount;

            if (charCount > 0x7fffffff)
                throw new ArgumentOutOfRangeException(nameof(byteCount), SR.ArgumentOutOfRange_GetCharCountOverflow);

            return (int)charCount;
        }