1 //------------------------------------------------------------------------------
2 // <copyright file="BuilderInfo.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
8 namespace System.Xml.Xsl.XsltOld {
9 using Res = System.Xml.Utils.Res;
11 using System.Diagnostics;
13 using System.Collections.Generic;
15 using System.Xml.XPath;
17 internal class BuilderInfo {
19 private string localName;
20 private string namespaceURI;
21 private string prefix;
23 private XmlNodeType nodeType;
25 private bool isEmptyTag;
27 internal string[] TextInfo = new string[4];
28 internal int TextInfoCount = 0;
31 internal HtmlElementProps htmlProps;
32 internal HtmlAttributeProps htmlAttrProps;
34 internal BuilderInfo() {
35 Initialize(string.Empty, string.Empty, string.Empty);
38 internal void Initialize(string prefix, string name, string nspace) {
40 this.localName = name;
41 this.namespaceURI = nspace;
43 this.htmlProps = null;
44 this.htmlAttrProps = null;
45 this.TextInfoCount = 0;
48 internal void Initialize(BuilderInfo src) {
49 this.prefix = src.Prefix;
50 this.localName = src.LocalName;
51 this.namespaceURI = src.NamespaceURI;
53 this.depth = src.Depth;
54 this.nodeType = src.NodeType;
55 this.htmlProps = src.htmlProps;
56 this.htmlAttrProps = src.htmlAttrProps;
58 this.TextInfoCount = 0;
59 EnsureTextInfoSize(src.TextInfoCount);
60 src.TextInfo.CopyTo(this.TextInfo, 0);
61 this.TextInfoCount = src.TextInfoCount;
64 void EnsureTextInfoSize(int newSize) {
65 if (this.TextInfo.Length < newSize) {
66 string[] newArr = new string[newSize * 2];
67 Array.Copy(this.TextInfo, newArr, this.TextInfoCount);
68 this.TextInfo = newArr;
72 internal BuilderInfo Clone() {
73 BuilderInfo info = new BuilderInfo();
74 info.Initialize(this);
75 Debug.Assert(info.NodeType != XmlNodeType.Text || XmlCharType.Instance.IsOnlyWhitespace(info.Value));
79 internal string Name {
81 if (this.name == null) {
82 string prefix = Prefix;
83 string localName = LocalName;
85 if (prefix != null && 0 < prefix.Length) {
86 if (localName.Length > 0) {
87 this.name = prefix + ":" + localName;
94 this.name = localName;
101 internal string LocalName {
102 get { return this.localName; }
103 set { this.localName = value; }
105 internal string NamespaceURI {
106 get { return this.namespaceURI; }
107 set { this.namespaceURI = value; }
109 internal string Prefix {
110 get { return this.prefix; }
111 set { this.prefix = value; }
114 // The true value of this object is a list of TextInfo
115 // Value.get merges them together but discards each node's escape info
116 // Value.set clears this object, and appends the new, single string
117 internal string Value {
119 switch (this.TextInfoCount) {
120 case 0: return string.Empty;
121 case 1: return this.TextInfo[0];
124 for (int i = 0; i < this.TextInfoCount; i++) {
125 string ti = this.TextInfo[i];
126 if (ti == null) continue; // ignore disableEscaping
129 StringBuilder sb = new StringBuilder(size);
130 for (int i = 0; i < this.TextInfoCount; i++) {
131 string ti = this.TextInfo[i];
132 if (ti == null) continue; // ignore disableEscaping
135 return sb.ToString();
139 this.TextInfoCount = 0;
140 ValueAppend(value, /*disableEscaping:*/false);
144 internal void ValueAppend(string s, bool disableEscaping) {
145 if (s == null || s.Length == 0) {
148 EnsureTextInfoSize(this.TextInfoCount + (disableEscaping ? 2 : 1));
149 if (disableEscaping) {
150 this.TextInfo[this.TextInfoCount ++] = null;
152 this.TextInfo[this.TextInfoCount++] = s;
155 internal XmlNodeType NodeType {
156 get { return this.nodeType; }
157 set { this.nodeType = value; }
160 get { return this.depth; }
161 set { this.depth = value; }
163 internal bool IsEmptyTag {
164 get { return this.isEmptyTag; }
165 set { this.isEmptyTag = value; }