public string Footer(bool outputformat = false) { if (this.SlashUsed || this.DirectClosed || this.AutoClosed) { return(null); } var text = new StringBuilder(); if (this.ElementType == TextElementType.ElementNode) { if (outputformat) { if (this.LastChild?.ElemName != "#text") { text.Append('\t', this.Depth); } } var eName = this.ElemName; if (!PhpFuctions.empty(this.AliasName)) { eName = this.AliasName; } text.Append(this.BaseEvulator.LeftTag.ToString() + '/' + eName + this.BaseEvulator.RightTag.ToString()); } if (outputformat) { text.Append("\r\n"); } return(text.ToString()); }
public string Outer(bool outputformat = false) { if (this.ElemName == "#document") { return(this.Inner()); } if (this.ElemName == "#text") { return(this.value); } if (this.ElementType == TextElementType.CommentNode) { return(this.BaseEvulator.LeftTag.ToString() + "--" + this.Value + "--" + this.BaseEvulator.RightTag.ToString()); } StringBuilder text = new StringBuilder(); StringBuilder additional = new StringBuilder(); if (!PhpFuctions.empty(this.TagAttrib)) { additional.Append("=" + this.TagAttrib); } if (this.ElementType == TextElementType.Parameter) { text.Append(this.BaseEvulator.LeftTag.ToString() + this.BaseEvulator.ParamChar.ToString() + this.ElemName + HTMLUTIL.ToAttribute(this.ElemAttr) + this.BaseEvulator.RightTag.ToString()); } else { if (this.AutoAdded) { if (this.SubElementsCount == 0) { return(string.Empty); } } text.Append(this.BaseEvulator.LeftTag.ToString() + this.ElemName + additional.ToString() + ((this.NoAttrib && this.ElementType == TextElementType.ElementNode) ? ' ' + this.Value : HTMLUTIL.ToAttribute(this.ElemAttr))); if (this.DirectClosed) { text.Append(" /" + this.BaseEvulator.RightTag); } else if (this.AutoClosed) { text.Append(this.BaseEvulator.RightTag); } else { text.Append(this.BaseEvulator.RightTag); text.Append(this.Inner(outputformat)); var eName = this.ElemName; if (!PhpFuctions.empty(this.AliasName)) { eName = this.AliasName; } text.Append(this.BaseEvulator.LeftTag + '/' + eName + this.BaseEvulator.RightTag.ToString()); } } return(text.ToString()); }
public string Header(bool outputformat = false) { if (this.AutoAdded && this.SubElementsCount == 0) { return(null); } StringBuilder text = new StringBuilder(); if (outputformat) { text.Append('\t', this.Depth); } if (this.ElementType == TextElementType.XMLTag) { text.Append(this.BaseEvulator.LeftTag.ToString() + "?" + this.ElemName + HTMLUTIL.ToAttribute(this.ElemAttr) + "?" + this.BaseEvulator.RightTag.ToString()); } if (this.ElementType == TextElementType.Parameter) { text.Append(this.BaseEvulator.LeftTag.ToString() + this.BaseEvulator.ParamChar.ToString() + this.ElemName + HTMLUTIL.ToAttribute(this.ElemAttr) + this.BaseEvulator.RightTag.ToString()); } else if (this.ElementType == TextElementType.ElementNode) { StringBuilder additional = new StringBuilder(); if (!PhpFuctions.empty(this.TagAttrib)) { additional.Append('=' + this.TagAttrib); } text.Append(this.BaseEvulator.LeftTag.ToString() + this.ElemName + additional.ToString() + ((this.NoAttrib) ? ' ' + this.Value : HTMLUTIL.ToAttribute(this.ElemAttr))); if (this.DirectClosed) { text.Append(" /" + this.BaseEvulator.RightTag.ToString()); } else if (this.AutoClosed) { text.Append(this.BaseEvulator.RightTag); } else { text.Append(this.BaseEvulator.RightTag); } } else if (this.ElementType == TextElementType.CDATASection) { text.Append(this.BaseEvulator.LeftTag.ToString() + "![CDATA[" + this.Value + "]]" + this.BaseEvulator.RightTag.ToString()); } else if (this.ElementType == TextElementType.CommentNode) { text.Append(this.BaseEvulator.LeftTag.ToString() + "--" + this.Value + "--" + this.BaseEvulator.RightTag.ToString()); } if (outputformat && this.FirstChild?.ElemName != "#text") { text.Append("\r\n"); } return(text.ToString()); }
private void ParseTagHeader(ref TextElement tagElement) { bool inquot = false; bool inspec = false; StringBuilder current = new StringBuilder(); bool namefound = false; //bool inattrib = false; bool firstslashused = false; bool lastslashused = false; StringBuilder currentName = new StringBuilder(); #pragma warning disable CS0219 // Değişken atandı ancak değeri hiç kullanılmadı bool quoted = false; #pragma warning restore CS0219 // Değişken atandı ancak değeri hiç kullanılmadı char quotchar = '\0'; bool initial = false; for (int i = this.pos; i < this.TextLength; i++) { var cur = this.Text[i]; if (inspec) { inspec = false; current.Append(cur); continue; } var next = '\0'; var next2 = '\0'; if (i + 1 < this.TextLength) { next = this.Text[i + 1]; } if (i + 2 < this.TextLength) { next2 = this.Text[i + 2]; } if (tagElement.ElementType == TextElementType.CDATASection) { if (cur == ']' && next == ']' && next2 == this.Evulator.RightTag) { tagElement.Value = current.ToString(); this.pos = i += 2; return; } current.Append(cur); continue; } if (this.Evulator.AllowXMLTag && cur == '?' && !namefound && current.Length == 0) { tagElement.Closed = true; tagElement.AutoClosed = true; tagElement.ElementType = TextElementType.XMLTag; continue; } if (this.Evulator.SupportExclamationTag && cur == '!' && !namefound && current.Length == 0) { tagElement.Closed = true; tagElement.AutoClosed = true; if (i + 8 < this.TextLength) { var mtn = this.Text.Substring(i, 8); if (this.Evulator.SupportCDATA && mtn == "![CDATA[") { tagElement.ElementType = TextElementType.CDATASection; tagElement.ElemName = "#cdata"; namefound = true; i += 7; continue; } } } if (cur == '\\' && tagElement.ElementType != TextElementType.CommentNode) { if (!namefound && tagElement.ElementType != TextElementType.Parameter) { this.Evulator.IsParseMode = false; throw new Exception("Syntax Error"); } inspec = true; continue; } if (!initial && cur == '!' && next == '-' && next2 == '-') { tagElement.ElementType = TextElementType.CommentNode; tagElement.ElemName = "#summary"; tagElement.Closed = true; i += 2; continue; } if (tagElement.ElementType == TextElementType.CommentNode) { if (cur == '-' && next == '-' && next2 == this.Evulator.RightTag) { tagElement.Value = current.ToString(); this.pos = i + 2; return; } else { current.Append(cur); } continue; } initial = true; if (this.Evulator.DecodeAmpCode && tagElement.ElementType != TextElementType.CommentNode && cur == '&') { current.Append(this.DecodeAmp(i + 1)); i = this.pos; continue; } if (tagElement.ElementType == TextElementType.Parameter && this.Evulator.ParamNoAttrib) { if (cur != this.Evulator.RightTag) { current.Append(cur); continue; } } if (namefound && tagElement.NoAttrib) { if (cur != this.Evulator.RightTag) { current.Append(cur); continue; } } if (firstslashused && namefound) { if (cur != this.Evulator.RightTag) { if (cur == ' ' && next != '\t' && next != ' ') { this.Evulator.IsParseMode = false; throw new Exception("Syntax Error"); } } } if (cur == '"' || cur == '\'') { if (!namefound || currentName.Length == 0) { this.Evulator.IsParseMode = false; throw new Exception("Syntax Error"); } if (inquot && cur == quotchar) { if (currentName.ToString() == "##set_TAG_ATTR##") { tagElement.TagAttrib = current.ToString(); } else if (currentName.Length > 0) { tagElement.ElemAttr.SetAttribute(currentName.ToString(), current.ToString()); } currentName.Clear(); current.Clear(); inquot = false; quoted = true; continue; } else if (!inquot) { quotchar = cur; inquot = true; continue; } } if (!inquot) { if (cur == this.Evulator.ParamChar && !namefound && !firstslashused) { tagElement.ElementType = TextElementType.Parameter; tagElement.Closed = true; continue; } if (cur == '/') { if (!namefound && current.Length > 0) { namefound = true; tagElement.ElemName = current.ToString(); current.Clear(); } if (namefound) { lastslashused = true; } else { firstslashused = true; } continue; } if (cur == '=') { if (namefound) { if (current.Length == 0) { this.Evulator.IsParseMode = false; throw new Exception("Syntax Error"); } currentName.Clear(); currentName.Append(current.ToString()); current.Clear(); } else { namefound = true; tagElement.ElemName = current.ToString(); current.Clear(); currentName.Clear(); currentName.Append("##set_TAG_ATTR##"); } continue; } if (tagElement.ElementType == TextElementType.XMLTag) { if (cur == '?' && next == this.Evulator.RightTag) { cur = next; i++; } } if (cur == this.Evulator.LeftTag) { this.Evulator.IsParseMode = false; throw new Exception("Syntax Error"); } if (cur == this.Evulator.RightTag) { if (!namefound) { tagElement.ElemName = current.ToString(); current.Clear(); } if (tagElement.NoAttrib) { tagElement.Value = current.ToString(); } else if (currentName.ToString() == "##set_TAG_ATTR##") { tagElement.TagAttrib = current.ToString(); } else if (currentName.Length > 0) { tagElement.SetAttribute(currentName.ToString(), current.ToString()); } else if (current.Length > 0) { tagElement.SetAttribute(current.ToString(), null); } tagElement.SlashUsed = firstslashused; if (lastslashused) { tagElement.DirectClosed = true; tagElement.Closed = true; } string elname = tagElement.ElemName.ToLowerInvariant(); if (this.Evulator.AutoClosedTags.Any(e => e.ToLowerInvariant() == elname)) { tagElement.Closed = true; tagElement.AutoClosed = true; } this.pos = i; return; } if (cur == ' ') { if (next == ' ' || next == '\t' || next == this.Evulator.RightTag) { continue; } if (!namefound && !PhpFuctions.empty(current)) { namefound = true; tagElement.ElemName = current.ToString(); current.Clear(); } else if (namefound) { if (currentName.ToString() == "##set_TAG_ATTR##") { tagElement.TagAttrib = current.ToString(); quoted = false; currentName.Clear(); current.Clear(); } else if (!PhpFuctions.empty(currentName)) { tagElement.SetAttribute(currentName.ToString(), current.ToString()); currentName.Clear(); current.Clear(); quoted = false; } else if (!PhpFuctions.empty(current)) { tagElement.SetAttribute(current.ToString(), null); current.Clear(); quoted = false; } } continue; } } current.Append(cur); } this.pos = this.TextLength; }