Exemple #1
0
        protected void Process(TextTokenId tokenId)
        {
#if DEBUG
            if (trace != null)
            {
                trace.TraceToken(parser.Token, 0);

                if (tokenId == TextTokenId.EndOfFile)
                {
                    trace.Flush();
                }
            }
#endif
            switch (tokenId)
            {
            case TextTokenId.Text:

                OutputFragmentSimple(parser.Token);
                break;

            case TextTokenId.EncodingChange:

                if (output != null && output.OutputCodePageSameAsInput)
                {
                    var codePage = parser.Token.Argument;

                        #if DEBUG
                    Encoding newOutputEncoding;

                    InternalDebug.Assert(Charset.TryGetEncoding(codePage, out newOutputEncoding));
                        #endif


                    output.OutputEncoding = Charset.GetEncoding(codePage);
                }
                break;

            case TextTokenId.EndOfFile:

                if (injection != null && injection.HaveTail)
                {
                    AddLineBreak(1);
                    InternalDebug.Assert(output != null);
                }

                // close the paragraph container
                CloseContainer();

                // close the document container
                CloseAllContainersAndSetEOF();
                break;
            }
        }
Exemple #2
0
        protected void Process(TextTokenId tokenId)
        {
#if DEBUG
            if (trace != null)
            {
                trace.TraceToken(parser.Token, 0);

                if (tokenId == TextTokenId.EndOfFile)
                {
                    trace.Flush();
                }
            }
#endif
            if (!started)
            {
                if (!convertFragment)
                {
                    output.OpenDocument();

                    if (injection != null && injection.HaveHead)
                    {
                        injection.Inject(true, output);
                    }
                }

                output.SetQuotingLevel(0);
                started = true;
            }

            switch (tokenId)
            {
            case TextTokenId.Text:

                OutputFragmentSimple(parser.Token);
                break;

            case TextTokenId.EncodingChange:

                if (!convertFragment)
                {
                    if (output.OutputCodePageSameAsInput)
                    {
                        var codePage = parser.Token.Argument;

                            #if DEBUG
                        Encoding newOutputEncoding;
                        // we should have already checked this in parser before reporting change
                        InternalDebug.Assert(Charset.TryGetEncoding(codePage, out newOutputEncoding));
                            #endif

                        output.OutputEncoding = Charset.GetEncoding(codePage);
                    }
                }
                break;

            case TextTokenId.EndOfFile:

                if (!convertFragment)
                {
                    if (injection != null && injection.HaveTail)
                    {
                        if (!output.LineEmpty)
                        {
                            output.OutputNewLine();
                        }

                        injection.Inject(false, output);
                    }

                    output.Flush();
                }
                else
                {
                    output.CloseParagraph();
                }

                endOfFile = true;

                break;
            }
        }