Tidy.Core.Lexer.GetCdata C# (CSharp) Method

GetCdata() public method

public GetCdata ( Node container ) : Node
container Node
return Node
        public virtual Node GetCdata(Node container)
        {
            int c, lastc, start;
            bool endtag = false;

            Lines = Input.CursorLine;
            Columns = Input.CursorColumn;
            Waswhite = false;
            Txtstart = Lexsize;
            Txtend = Lexsize;

            lastc = '\x0000';
            start = - 1;

            while (true)
            {
                c = Input.ReadChar();
                if (c == StreamIn.END_OF_STREAM)
                {
                    break;
                }
                /* treat \r\n as \n and \r as \n */

                if (c == '/' && lastc == '<')
                {
                    if (endtag)
                    {
                        Lines = Input.CursorLine;
                        Columns = Input.CursorColumn - 3;

                        Report.Warning(this, null, null, Report.BAD_CDATA_CONTENT);
                    }

                    start = Lexsize + 1; /* to first letter */
                    endtag = true;
                }
                else if (c == '>' && start >= 0)
                {
                    int len = Lexsize - start;
                    if (len == container.Element.Length)
                    {
                        string str = GetString(Lexbuf, start, len);
                        if (String.CompareOrdinal(str, container.Element) == 0)
                        {
                            Txtend = start - 2;
                            break;
                        }
                    }

                    Lines = Input.CursorLine;
                    Columns = Input.CursorColumn - 3;

                    Report.Warning(this, null, null, Report.BAD_CDATA_CONTENT);

                    /* if javascript insert backslash before / */

                    if (ParserImpl.IsJavaScript(container))
                    {
                        int i;
                        for (i = Lexsize; i > start - 1; --i)
                        {
                            Lexbuf[i] = Lexbuf[i - 1];
                        }

                        Lexbuf[start - 1] = (byte) '\\';
                        Lexsize++;
                    }

                    start = - 1;
                }
                else if (c == '\r')
                {
                    c = Input.ReadChar();

                    if (c != '\n')
                    {
                        Input.UngetChar(c);
                    }

                    c = '\n';
                }

                AddCharToLexer(c);
                Txtend = Lexsize;
                lastc = c;
            }

            if (c == StreamIn.END_OF_STREAM)
            {
                Report.Warning(this, container, null, Report.MISSING_ENDTAG_FOR);
            }

            if (Txtend > Txtstart)
            {
                Token = NewNode(Node.TEXT_NODE, Lexbuf, Txtstart, Txtend);
                return Token;
            }

            return null;
        }

Usage Example

Beispiel #1
0
            public virtual void Parse(Lexer lexer, Node script, short mode)
            {
                /*
                This isn't quite right for CDATA content as it recognises
                tags within the content and parses them accordingly.
                This will unfortunately screw up scripts which include
                < + letter,  < + !, < + ?  or  < + / + letter
                */

                Node node = lexer.GetCdata(script);

                if (node != null)
                {
                    Node.InsertNodeAtEnd(script, node);
                }
            }