internal void ChangeEncoding(Encoding newEncoding)
        {
            if (this.encoding != null)
            {
                this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferCount, true);
                this.lineBufferCount = 0;
            }
            this.encoding = newEncoding;
            this.encoder  = newEncoding.GetEncoder();
            int codePage = CodePageMap.GetCodePage(newEncoding);

            if (codePage == 1200 || codePage == 1201 || codePage == 12000 || codePage == 12001 || codePage == 65000 || codePage == 65001 || codePage == 65005 || codePage == 65006 || codePage == 54936)
            {
                this.lineModeEncoding        = false;
                this.encodingCompleteUnicode = true;
                this.codePageMap.ChoseCodePage(1200);
                return;
            }
            this.encodingCompleteUnicode = false;
            this.codePageMap.ChoseCodePage(codePage);
            if (codePage == 50220 || codePage == 50221 || codePage == 50222 || codePage == 50225 || codePage == 50227 || codePage == 50229 || codePage == 52936)
            {
                this.lineModeEncoding = true;
            }
        }
        public void SetCharset(Charset detectedCharset)
        {
            if (this.toHtmlConverter == null)
            {
                throw new InvalidOperationException("HtmlWriteConverterStream.SetCharset() should only be called once.");
            }
            HtmlToHtml htmlToHtml = this.toHtmlConverter as HtmlToHtml;

            if (htmlToHtml != null)
            {
                if (CodePageMap.GetCodePage(htmlToHtml.InputEncoding) == detectedCharset.CodePage && this.skipConversionOnMatchingCharset)
                {
                    this.writeStream = this.outputStream;
                }
                else
                {
                    htmlToHtml.OutputEncoding = detectedCharset.GetEncoding();
                    this.writeStream          = new ConverterStream(this.outputStream, htmlToHtml, ConverterStreamAccess.Write);
                }
            }
            else
            {
                RtfToHtml rtfToHtml = this.toHtmlConverter as RtfToHtml;
                if (rtfToHtml != null)
                {
                    rtfToHtml.OutputEncoding = detectedCharset.GetEncoding();
                }
                else
                {
                    TextToHtml textToHtml = this.toHtmlConverter as TextToHtml;
                    if (textToHtml != null)
                    {
                        textToHtml.OutputEncoding = detectedCharset.GetEncoding();
                    }
                }
                this.writeStream = new ConverterStream(this.outputStream, this.toHtmlConverter, ConverterStreamAccess.Write);
            }
            this.toHtmlConverter = null;
            this.cachedContentStream.Position = 0L;
            Util.StreamHandler.CopyStreamData(this.cachedContentStream, this.writeStream);
            this.cachedContentStream.Dispose();
            this.cachedContentStream = null;
        }
            // Token: 0x06000848 RID: 2120 RVA: 0x0002DBD4 File Offset: 0x0002BDD4
            public void Write(char[] charBuffer, int charOffset, int charCount, byte[] buffer, int byteCount)
            {
                bool flag  = false;
                int  num   = 1;
                int  num2  = 0;
                int  num3  = 0;
                bool flag2 = false;

                if (buffer == null)
                {
                    buffer = new byte[this.encoder.GetByteCount(charBuffer, charOffset, charCount, false)];
                    this.encoder.GetBytes(charBuffer, charOffset, charCount, buffer, 0, false);
                }
                if (byteCount == -1)
                {
                    byteCount = buffer.Length;
                }
                while (byteCount > 0 && num3 < charBuffer.Length)
                {
                    switch (this.state)
                    {
                    case ContentLineWriter.FoldingTextWriter.States.Normal:
                    {
                        if (flag || this.linePosition == 75)
                        {
                            if (flag)
                            {
                                flag = false;
                            }
                            if (charBuffer[num3] == '\r')
                            {
                                num3++;
                                this.state = ContentLineWriter.FoldingTextWriter.States.CR;
                                this.baseStream.WriteByte(buffer[num2++]);
                                byteCount--;
                                break;
                            }
                            this.baseStream.Write(this.foldingBytes, 0, this.foldingBytes.Length);
                            this.linePosition = 1;
                        }
                        int num4     = Math.Min(75 - this.linePosition, byteCount);
                        int num5     = num2;
                        int codePage = CodePageMap.GetCodePage(this.encoding);
                        while (num2 - num5 < num4)
                        {
                            bool flag3 = false;
                            if (num3 == charBuffer.Length)
                            {
                                break;
                            }
                            int num6 = codePage;
                            if (num6 != 1200)
                            {
                                switch (num6)
                                {
                                case 65000:
                                    if (!flag2)
                                    {
                                        if (num3 == charBuffer.Length - 1)
                                        {
                                            flag2 = true;
                                        }
                                        num = this.WriteCharIntoBytes(charBuffer[num3], flag2);
                                    }
                                    break;

                                case 65001:
                                    if (charBuffer[num3] < '\u0080')
                                    {
                                        num = 1;
                                    }
                                    else if (charBuffer[num3] < 'ࠀ')
                                    {
                                        num = 2;
                                    }
                                    else if (char.IsHighSurrogate(charBuffer[num3]))
                                    {
                                        if (num3 < charBuffer.Length - 1 && char.IsLowSurrogate(charBuffer[num3 + 1]))
                                        {
                                            flag3 = true;
                                            if (buffer[num2] < 248)
                                            {
                                                num = 4;
                                            }
                                            else if (buffer[num2] < 252)
                                            {
                                                num = 5;
                                            }
                                            else
                                            {
                                                num = 6;
                                            }
                                        }
                                    }
                                    else if (ContentLineWriter.FoldingTextWriter.IsInvalidUTF8Byte(charBuffer[num3], buffer, num2))
                                    {
                                        num = 1;
                                    }
                                    else
                                    {
                                        num = 3;
                                    }
                                    break;

                                default:
                                    num = this.WriteCharIntoBytes(charBuffer[num3], false);
                                    break;
                                }
                            }
                            else if (this.linePosition + num2 - num5 > 71 && char.IsHighSurrogate(charBuffer[num3]))
                            {
                                flag = true;
                            }
                            else
                            {
                                num = 2;
                            }
                            if (flag)
                            {
                                break;
                            }
                            if (this.linePosition + (num2 - num5) + num > 75)
                            {
                                flag = true;
                                break;
                            }
                            num2 += num;
                            if (flag3)
                            {
                                num3++;
                            }
                            if (charBuffer[num3++] == '\r')
                            {
                                this.state = ContentLineWriter.FoldingTextWriter.States.CR;
                                break;
                            }
                        }
                        int num7 = num2 - num5;
                        this.baseStream.Write(buffer, num5, num7);
                        this.linePosition += num7;
                        byteCount         -= num7;
                        break;
                    }

                    case ContentLineWriter.FoldingTextWriter.States.CR:
                        this.baseStream.WriteByte(buffer[num2]);
                        if (charBuffer[num3++] == '\n')
                        {
                            this.linePosition = 0;
                            this.state        = ContentLineWriter.FoldingTextWriter.States.Normal;
                        }
                        else
                        {
                            if (this.linePosition == 75 || flag)
                            {
                                if (flag)
                                {
                                    flag = false;
                                }
                                this.baseStream.Write(this.foldingBytes, 0, this.foldingBytes.Length);
                                this.linePosition = 1;
                            }
                            else
                            {
                                this.linePosition++;
                            }
                            if (num3 < charBuffer.Length && charBuffer[num3] != '\r')
                            {
                                this.state = ContentLineWriter.FoldingTextWriter.States.Normal;
                            }
                        }
                        num2++;
                        byteCount--;
                        break;
                    }
                }
            }