⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sgmlreader.cs

📁 Freetextbox是优秀的在线编辑器
💻 CS
📖 第 1 页 / 共 4 页
字号:
                                break;
                            }
                            this.sb.Length = 0;
                            this.sb.Append(text1);
                            this.sb.Append("</" + this.endTag + ">");
                            flag1 = false;
                            goto Label_02D0;
                        }
                    }
                    this.sb.Append('<');
                    this.sb.Append(ch1);
                    flag1 = false;
                }
                else
                {
                    if (!(this.current.IsWhitespace || !flag1))
                    {
                        flag1 = false;
                    }
                    this.sb.Append(ch1);
                }
            Label_02D0:
                ch1 = this.current.ReadChar();
            }
            string text2 = this.sb.ToString();
            this.Push(null, XmlNodeType.CDATA, text2);
            if (this.partial == '\0')
            {
                this.partial = ' ';
            }
            return true;
        }

        private bool ParseComment()
        {
            char ch1 = this.current.ReadChar();
            if (ch1 != '-')
            {
                this.Log("Expecting comment '<!--' but found {0}", ch1);
                this.current.ScanToEnd(null, "Comment", ">");
                return false;
            }
            string text1 = this.current.ScanToEnd(this.sb, "Comment", "-->");
            for (int num1 = text1.IndexOf("--"); num1 >= 0; num1 = text1.IndexOf("--"))
            {
                int num2 = num1 + 2;
                while ((num2 < text1.Length) && (text1[num2] == '-'))
                {
                    num2++;
                }
                if (num1 > 0)
                {
                    text1 = text1.Substring(0, num1 - 1) + "-" + text1.Substring(num2);
                }
                else
                {
                    text1 = "-" + text1.Substring(num2);
                }
            }
            if ((text1.Length > 0) && (text1[text1.Length - 1] == '-'))
            {
                text1 = text1 + " ";
            }
            this.Push(null, XmlNodeType.Comment, text1);
            return true;
        }

        private bool ParseConditionalBlock()
        {
            char ch1 = this.current.ReadChar();
            ch1 = this.current.SkipWhitespace();
            string text1 = this.current.ScanToken(this.sb, SgmlReader.cdataterm, false);
            if (text1 != "CDATA")
            {
                this.Log("Expecting CDATA but found '{0}'", new string[] { text1 });
                this.current.ScanToEnd(null, "CDATA", ">");
                return false;
            }
            ch1 = this.current.SkipWhitespace();
            if (ch1 != '[')
            {
                this.Log("Expecting '[' but found '{0}'", ch1);
                this.current.ScanToEnd(null, "CDATA", ">");
                return false;
            }
            string text2 = this.current.ScanToEnd(this.sb, "CDATA", "]]>");
            this.Push(null, XmlNodeType.CDATA, text2);
            return true;
        }

        private void ParseDocType()
        {
            char ch1 = this.current.SkipWhitespace();
            string text1 = this.ScanName(SgmlReader.dtterm);
            this.Push(text1, XmlNodeType.DocumentType, null);
            ch1 = this.current.SkipWhitespace();
            if (ch1 != '>')
            {
                string text2 = "";
                string text3 = "";
                string text4 = "";
                if (ch1 != '[')
                {
                    string text5 = this.ScanName(SgmlReader.dtterm);
                    if (text5 == "PUBLIC")
                    {
                        ch1 = this.current.SkipWhitespace();
                        if ((ch1 == '"') || (ch1 == '\''))
                        {
                            text3 = this.current.ScanLiteral(this.sb, ch1);
                            this.node.AddAttribute(text5, text3, ch1, this.folding == FreeTextBoxControls.Support.Sgml.CaseFolding.None);
                        }
                    }
                    else if (text5 != "SYSTEM")
                    {
                        this.Log("Unexpected token in DOCTYPE '{0}'", new string[] { text5 });
                        this.current.ScanToEnd(null, "DOCTYPE", ">");
                    }
                    ch1 = this.current.SkipWhitespace();
                    if ((ch1 == '"') || (ch1 == '\''))
                    {
                        text5 = this.nametable.Add("SYSTEM");
                        text4 = this.current.ScanLiteral(this.sb, ch1);
                        this.node.AddAttribute(text5, text4, ch1, this.folding == FreeTextBoxControls.Support.Sgml.CaseFolding.None);
                    }
                    ch1 = this.current.SkipWhitespace();
                }
                if (ch1 == '[')
                {
                    text2 = this.current.ScanToEnd(this.sb, "Internal Subset", "]");
                    this.node.Value = text2;
                }
                ch1 = this.current.SkipWhitespace();
                if (ch1 != '>')
                {
                    this.Log("Expecting end of DOCTYPE tag, but found '{0}'", ch1);
                    this.current.ScanToEnd(null, "DOCTYPE", ">");
                }
                if (this.dtd == null)
                {
                    this.docType = text1;
                    this.pubid = text3;
                    this.syslit = text4;
                    this.subset = text2;
                    this.LazyLoadDtd(this.current.ResolvedUri);
                }
            }
            this.current.ReadChar();
        }

        private bool ParseEndTag()
        {
            this.state = FreeTextBoxControls.Support.Sgml.State.EndTag;
            this.current.ReadChar();
            string text1 = this.ScanName(SgmlReader.tagterm);
            char ch1 = this.current.SkipWhitespace();
            if (ch1 != '>')
            {
                this.Log("Expected empty start tag '/>' sequence instead of '{0}'", ch1);
                this.current.ScanToEnd(null, "Recovering", ">");
            }
            this.current.ReadChar();
            this.endTag = text1;
            bool flag1 = this.folding == FreeTextBoxControls.Support.Sgml.CaseFolding.None;
            this.node = (Node) this.stack[this.stack.Count - 1];
            for (int num1 = this.stack.Count - 1; num1 > 0; num1--)
            {
                Node node1 = (Node) this.stack[num1];
                if (flag1 && (string.Compare(node1.Name, text1, true) == 0))
                {
                    this.endTag = node1.Name;
                    return true;
                }
                if (node1.Name == text1)
                {
                    return true;
                }
            }
            this.Log("No matching start tag for '</{0}>'", new string[] { text1 });
            this.state = FreeTextBoxControls.Support.Sgml.State.Markup;
            return false;
        }

        private bool ParseMarkup()
        {
            char ch1 = this.current.Lastchar;
            switch (ch1)
            {
                case '<':
                    ch1 = this.current.ReadChar();
                    return this.ParseTag(ch1);

                case 0xffff:
                    this.state = FreeTextBoxControls.Support.Sgml.State.Eof;
                    return false;
            }
            if ((this.node.DtdType != null) && (this.node.DtdType.ContentModel.DeclaredContent == DeclaredContent.CDATA))
            {
                this.partial = '\0';
                this.state = FreeTextBoxControls.Support.Sgml.State.CData;
                return false;
            }
            if (this.ParseText(ch1, true))
            {
                this.node.NodeType = XmlNodeType.Whitespace;
            }
            return true;
        }

        private bool ParsePI()
        {
            string text1 = this.current.ScanToken(this.sb, SgmlReader.piterm, false);
            string text2 = null;
            if (this.current.Lastchar != '?')
            {
                text2 = this.current.ScanToEnd(this.sb, "Processing Instruction", ">");
            }
            else
            {
                text2 = this.current.ScanToEnd(this.sb, "Processing Instruction", ">");
            }
            if (text1 != "xml")
            {
                this.Push(this.nametable.Add(text1), XmlNodeType.ProcessingInstruction, text2);
                return true;
            }
            return false;
        }

        private bool ParseStartTag(char ch)
        {
            string text1 = null;
            if (this.state != FreeTextBoxControls.Support.Sgml.State.PseudoStartTag)
            {
                if (SgmlReader.tagterm.IndexOf(ch) >= 0)
                {
                    this.sb.Length = 0;
                    this.sb.Append('<');
                    this.state = FreeTextBoxControls.Support.Sgml.State.PartialText;
                    return false;
                }
                text1 = this.ScanName(SgmlReader.tagterm);
                if (((this.IsHtml && (this.Depth == 0)) && (text1 != "html")) && (text1 != "HTML"))
                {
                    Node node1 = this.Push("html", XmlNodeType.Element, null);
                    node1.IsEmpty = false;
                    this.state = FreeTextBoxControls.Support.Sgml.State.PseudoStartTag;
                    this.startTag = text1;
                    return true;
                }
            }
            else
            {
                text1 = this.startTag;
                this.state = FreeTextBoxControls.Support.Sgml.State.Markup;
            }
            Node node2 = this.Push(text1, XmlNodeType.Element, null);
            node2.IsEmpty = false;
            this.Validate(node2);
            ch = this.current.SkipWhitespace();
            while ((ch != 0xffff) && (ch != '>'))
            {
                if (ch == '/')
                {
                    node2.IsEmpty = true;
                    ch = this.current.ReadChar();
                    if (ch != '>')
                    {
                        this.Log("Expected empty start tag '/>' sequence instead of '{0}'", ch);
                        this.current.ScanToEnd(null, "Recovering", ">");
                        return false;
                    }
                    break;
                }
                if (ch == '<')
                {
                    this.Log("Start tag '{0}' is missing '>'", new string[] { text1 });
                    break;
                }
                string text2 = this.ScanName(SgmlReader.aterm);
                ch = this.current.SkipWhitespace();
                string text3 = null;
                char ch1 = '\0';
                if (ch == '=')
                {
                    this.current.ReadChar();
                    ch = this.current.SkipWhitespace();
                    if ((ch == '\'') || (ch == '"'))
                    {
                        ch1 = ch;
                        text3 = this.ScanLiteral(this.sb, ch);
                    }
                    else if (ch != '>')
                    {
                        string text4 = SgmlReader.avterm;
                        text3 = this.current.ScanToken(this.sb, text4, false);
                    }
                }
                if (text2.Length > 0)
                {
                    FreeTextBoxControls.Support.Sgml.Attribute attribute1 = node2.AddAttribute(text2, text3, ch1, this.folding == FreeTextBoxControls.Support.Sgml.CaseFolding.None);
                    if (attribute1 == null)
                    {
                        this.Log("Duplicate attribute '{0}' ignored", new string[] { text2 });
                    }
                    else
                    {
                        this.ValidateAttribute(node2, attribute1);
                    }
                }
                ch = this.current.SkipWhitespace();
            }
            if (ch == 0xffff)
            {
                this.current.Error("Unexpected EOF parsing start tag '{0}'", text1);
            }
            else if (ch == '>')
            {
                this.current.ReadChar();
            }
            if (this.Depth == 1)
            {
                if (this.rootCount == 1)
                {
                    this.state = FreeTextBoxControls.Support.Sgml.State.Eof;
                    return false;
                }
                this.rootCount++;
            }
            this.ValidateContent(node2);
            return true;
        }

        private bool ParseTag(char ch)
        {
            if (ch == '%')
            {
                return this.ParseAspNet();
            }
            if (ch == '!')
            {
                ch = this.current.ReadChar();
                if (ch == '-')
                {
                    return this.ParseComment();
                }
                if (ch == '[')
                {
                    return this.ParseConditionalBlock();
                }
                if (!((ch == '_') || char.IsLetter(ch)))
                {
                    string text1 = this.current.ScanToEnd(this.sb, "Recovering", ">");
                    this.Log("Ignoring invalid markup '<!" + text1 + ">", new string[0]);
                    return false;
                }
                string text2 = this.current.ScanToken(this.sb, SgmlReader.declterm, false);
                if (text2 == "DOCTYPE")
                {
                    this.ParseDocType();
                    if ((this.GetAttribute("SYSTEM") == null) && (this.GetAttribute("PUBLIC") != null))
                    {
                        this.node.AddAttribute("SYSTEM", "", '"', this.folding == FreeTextBoxControls.Support.Sgml.CaseFolding.None);
                    }
                    if (this.stripDocType)
                    {
                        return false;
                    }
                    this.node.NodeType = XmlNodeType.DocumentType;
                    return true;
                }
                this.Log("Invalid declaration '<!{0}...'.  Expecting '<!DOCTYPE' only.", new string[] { text2 });
                this.current.ScanToEnd(null, "Recovering", ">");
                return false;
            }
            if (ch == '?')
            {
                this.current.ReadChar();
                this.ParsePI();
            }
            else
            {
                if (ch == '/')
                {
                    return this.ParseEndTag();
                }
                return this.ParseStartTag(ch);
            }
            return true;
        }

        private bool ParseText(char ch, bool newtext)
        {
            bool flag1 = !newtext || this.current.IsWhitespace;
            if (newtext)
            {
                this.sb.Length = 0;
            }
            this.state = FreeTextBoxControls.Support.Sgml.State.Text;
            while (ch != 0xffff)
            {
                if (ch == '<')
                {
                    ch = this.current.ReadChar();
                    if ((((ch == '/') || (ch == '!')) || (ch == '?')) || char.IsLetter(ch))
                    {
                        this.state = FreeTextBoxControls.Support.Sgml.State.PartialTag;
                        this.partial = ch;
                        break;
                    }
                    this.sb.Append('<');
                    this.sb.Append(ch);
                    flag1 = false;
                    ch = this.current.ReadChar();
                }
                else if (ch == '&')
                {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -