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

📄 sgmlreader.cs

📁 Freetextbox是优秀的在线编辑器
💻 CS
📖 第 1 页 / 共 4 页
字号:
                    this.ExpandEntity(this.sb, '<');
                    flag1 = false;
                    ch = this.current.Lastchar;
                }
                else
                {
                    if (!this.current.IsWhitespace)
                    {
                        flag1 = false;
                    }
                    this.sb.Append(ch);
                    ch = this.current.ReadChar();
                }
            }
            string text1 = this.sb.ToString();
            this.Push(null, XmlNodeType.Text, text1);
            return flag1;
        }

        private void Pop()
        {
            if (this.stack.Count > 1)
            {
                this.node = (Node) this.stack.Pop();
            }
        }

        private Node Push(Node n)
        {
            Node node1 = this.Push(n.Name, n.NodeType, n.Value);
            node1.DtdType = n.DtdType;
            node1.IsEmpty = n.IsEmpty;
            node1.Space = n.Space;
            node1.XmlLang = n.XmlLang;
            node1.CurrentState = n.CurrentState;
            node1.CopyAttributes(n);
            this.node = node1;
            return node1;
        }

        private Node Push(string name, XmlNodeType nt, string value)
        {
            Node node1 = (Node) this.stack.Push();
            if (node1 == null)
            {
                node1 = new Node();
                this.stack[this.stack.Count - 1] = node1;
            }
            node1.Reset(name, nt, value);
            this.node = node1;
            return node1;
        }

        public override bool Read()
        {
            if (this.current == null)
            {
                this.OpenInput();
            }
            bool flag1 = false;
            while (!flag1)
            {
                switch (this.state)
                {
                    case FreeTextBoxControls.Support.Sgml.State.Initial:
                        this.state = FreeTextBoxControls.Support.Sgml.State.Markup;
                        this.current.ReadChar();
                        goto Label_00F2;

                    case FreeTextBoxControls.Support.Sgml.State.Markup:
                        goto Label_00F2;

                    case FreeTextBoxControls.Support.Sgml.State.EndTag:
                        if (this.endTag != this.node.Name)
                        {
                            break;
                        }
                        this.Pop();
                        this.state = FreeTextBoxControls.Support.Sgml.State.Markup;
                        goto Label_00F2;

                    case FreeTextBoxControls.Support.Sgml.State.Attr:
                        goto Label_018F;

                    case FreeTextBoxControls.Support.Sgml.State.AttrValue:
                        goto Label_0191;

                    case FreeTextBoxControls.Support.Sgml.State.Text:
                        this.Pop();
                        goto Label_00F2;

                    case FreeTextBoxControls.Support.Sgml.State.PartialTag:
                        this.Pop();
                        this.state = FreeTextBoxControls.Support.Sgml.State.Markup;
                        flag1 = this.ParseTag(this.partial);
                        goto Label_01D5;

                    case FreeTextBoxControls.Support.Sgml.State.AutoClose:
                        this.Pop();
                        if (this.stack.Count <= this.poptodepth)
                        {
                            this.state = FreeTextBoxControls.Support.Sgml.State.Markup;
                            this.Push(this.newnode);
                            this.state = FreeTextBoxControls.Support.Sgml.State.Markup;
                        }
                        flag1 = true;
                        goto Label_01D5;

                    case FreeTextBoxControls.Support.Sgml.State.CData:
                        flag1 = this.ParseCData();
                        goto Label_01D5;

                    case FreeTextBoxControls.Support.Sgml.State.PartialText:
                        goto Label_01A9;

                    case FreeTextBoxControls.Support.Sgml.State.PseudoStartTag:
                        flag1 = this.ParseStartTag('<');
                        goto Label_01D5;

                    case FreeTextBoxControls.Support.Sgml.State.Eof:
                        if (this.current.Parent == null)
                        {
                            return false;
                        }
                        this.current.Close();
                        this.current = this.current.Parent;
                        goto Label_01D5;

                    default:
                        goto Label_01D5;
                }
                this.Pop();
                flag1 = true;
                goto Label_01D5;
            Label_00F2:
                if (this.node.IsEmpty)
                {
                    this.Pop();
                }
                flag1 = this.ParseMarkup();
                goto Label_01D5;
            Label_018F:;
            Label_0191:
                this.state = FreeTextBoxControls.Support.Sgml.State.Markup;
                goto Label_00F2;
            Label_01A9:
                if (this.ParseText(this.current.Lastchar, false))
                {
                    this.node.NodeType = XmlNodeType.Whitespace;
                }
                flag1 = true;
            Label_01D5:
                if ((flag1 && (this.node.NodeType == XmlNodeType.Whitespace)) && (this.whitespaceHandling == System.Xml.WhitespaceHandling.None))
                {
                    flag1 = false;
                }
            }
            return true;
        }

        public override bool ReadAttributeValue()
        {
            if (this.state == FreeTextBoxControls.Support.Sgml.State.Attr)
            {
                this.state = FreeTextBoxControls.Support.Sgml.State.AttrValue;
                return true;
            }
            if (this.state != FreeTextBoxControls.Support.Sgml.State.AttrValue)
            {
                throw new InvalidOperationException("Not on an attribute.");
            }
            return false;
        }

        public override string ReadInnerXml()
        {
            StringWriter writer1 = new StringWriter();
            XmlTextWriter writer2 = new XmlTextWriter(writer1);
            writer2.Formatting = Formatting.Indented;
            switch (this.NodeType)
            {
                case XmlNodeType.Element:
                    this.Read();
                    while (!this.EOF && (this.NodeType != XmlNodeType.EndElement))
                    {
                        writer2.WriteNode(this, true);
                    }
                    this.Read();
                    break;

                case XmlNodeType.Attribute:
                    writer1.Write(this.Value);
                    break;
            }
            writer2.Close();
            return writer1.ToString();
        }

        public override string ReadOuterXml()
        {
            StringWriter writer1 = new StringWriter();
            XmlTextWriter writer2 = new XmlTextWriter(writer1);
            writer2.Formatting = Formatting.Indented;
            writer2.WriteNode(this, true);
            writer2.Close();
            return writer1.ToString();
        }

        public override string ReadString()
        {
            if (this.node.NodeType == XmlNodeType.Element)
            {
                this.sb.Length = 0;
                while (this.Read())
                {
                    switch (this.NodeType)
                    {
                        case XmlNodeType.Text:
                        case XmlNodeType.CDATA:
                        case XmlNodeType.Whitespace:
                        case XmlNodeType.SignificantWhitespace:
                            this.sb.Append(this.node.Value);
                            break;

                        default:
                            return this.sb.ToString();
                    }
                }
                return this.sb.ToString();
            }
            return this.node.Value;
        }

        public override void ResolveEntity()
        {
            throw new InvalidOperationException("Not on an entity reference.");
        }

        public string ScanLiteral(StringBuilder sb, char quote)
        {
            sb.Length = 0;
            char ch1 = this.current.ReadChar();
            while ((ch1 != 0xffff) && (ch1 != quote))
            {
                if (ch1 == '&')
                {
                    this.ExpandEntity(this.sb, quote);
                    ch1 = this.current.Lastchar;
                }
                else
                {
                    sb.Append(ch1);
                    ch1 = this.current.ReadChar();
                }
            }
            this.current.ReadChar();
            return sb.ToString();
        }

        private string ScanName(string terminators)
        {
            string text1 = this.current.ScanToken(this.sb, terminators, false);
            switch (this.folding)
            {
                case FreeTextBoxControls.Support.Sgml.CaseFolding.ToUpper:
                    text1 = text1.ToUpper();
                    break;

                case FreeTextBoxControls.Support.Sgml.CaseFolding.ToLower:
                    text1 = text1.ToLower();
                    break;
            }
            return this.nametable.Add(text1);
        }

        public void SetBaseUri(string uri)
        {
            this.baseUri = new Uri(uri);
        }

        private void Validate(Node node)
        {
            if (this.dtd != null)
            {
                ElementDecl decl1 = this.dtd.FindElement(node.Name);
                if (decl1 != null)
                {
                    node.DtdType = decl1;
                    if (decl1.ContentModel.DeclaredContent == DeclaredContent.EMPTY)
                    {
                        node.IsEmpty = true;
                    }
                }
            }
        }

        private void ValidateAttribute(Node node, FreeTextBoxControls.Support.Sgml.Attribute a)
        {
            ElementDecl decl1 = node.DtdType;
            if (decl1 != null)
            {
                AttDef def1 = decl1.FindAttribute(a.Name);
                if (def1 != null)
                {
                    a.DtdType = def1;
                }
            }
        }

        private void ValidateContent(Node node)
        {
            if (this.dtd != null)
            {
                Node node1;
                string text1 = this.nametable.Add(node.Name.ToUpper());
                int num1 = 0;
                int num2 = this.stack.Count - 2;
                if (node.DtdType != null)
                {
                    for (num1 = num2; num1 > 0; num1--)
                    {
                        node1 = (Node) this.stack[num1];
                        if (!node1.IsEmpty)
                        {
                            ElementDecl decl1 = node1.DtdType;
                            if (((decl1 == null) || (decl1.Name == this.dtd.Name)) || (decl1.CanContain(text1, this.dtd) || !decl1.EndTagOptional))
                            {
                                break;
                            }
                        }
                    }
                }
                if ((num1 != 0) && (num1 < num2))
                {
                    node1 = (Node) this.stack[num2];
                    if ((num1 != (num2 - 1)) || (text1 != node1.Name))
                    {
                        string text2 = "";
                        for (int num3 = num2; num3 >= (num1 + 1); num3--)
                        {
                            if (text2 != "")
                            {
                                text2 = text2 + ",";
                            }
                            Node node2 = (Node) this.stack[num3];
                            text2 = text2 + "<" + node2.Name + ">";
                        }
                        this.Log("Element '{0}' not allowed inside '{1}', closing {2}.", new string[] { text1, node1.Name, text2 });
                    }
                    this.state = FreeTextBoxControls.Support.Sgml.State.AutoClose;
                    this.newnode = node;
                    this.Pop();
                    this.poptodepth = num1 + 1;
                }
            }
        }


        public override int AttributeCount
        {
            get
            {
                if (((this.state != FreeTextBoxControls.Support.Sgml.State.Attr) && (this.state != FreeTextBoxControls.Support.Sgml.State.AttrValue)) && ((this.node.NodeType == XmlNodeType.Element) || (this.node.NodeType == XmlNodeType.DocumentType)))
                {
                    return this.node.AttributeCount;
                }
                return 0;
            }
        }

        public override string BaseURI
        {
            get
            {
                return ((this.baseUri == null) ? "" : this.baseUri.AbsoluteUri);
            }
        }

        public FreeTextBoxControls.Support.Sgml.CaseFolding CaseFolding
        {
            get
            {
                return this.folding;
            }
            set
            {
                this.folding = value;
            }
        }

        public override int Depth
        {
            get
            {
                if (this.state == FreeTextBoxControls.Support.Sgml.State.Attr)
                {
                    return this.stack.Count;
                }
                if (this.state == FreeTextBoxControls.Support.Sgml.State.AttrValue)
                {
                    return (this.stack.Count + 1);
                }
                return (this.stack.Count - 1);
            }
        }

        public string DocType
        {
            get
            {
                return this.docType;
            }
            set
            {
                this.docType = value;
            }
        }

⌨️ 快捷键说明

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