Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NamespaceList.cs
Go to the documentation of this file.
2using System.Text;
3
4namespace System.Xml.Schema;
5
6internal class NamespaceList
7{
8 public enum ListType
9 {
10 Any,
11 Other,
12 Set
13 }
14
15 private ListType _type;
16
17 private Hashtable _set;
18
19 private readonly string _targetNamespace;
20
21 public ListType Type => _type;
22
23 public string Excluded => _targetNamespace;
24
26 {
27 get
28 {
30 if ((uint)type > 1u && type == ListType.Set)
31 {
32 return _set.Keys;
33 }
34 throw new InvalidOperationException();
35 }
36 }
37
39 {
40 }
41
43 {
45 namespaces = namespaces.Trim();
46 if (namespaces == "##any" || namespaces.Length == 0)
47 {
48 _type = ListType.Any;
49 return;
50 }
51 if (namespaces == "##other")
52 {
53 _type = ListType.Other;
54 return;
55 }
56 _type = ListType.Set;
57 _set = new Hashtable();
59 for (int i = 0; i < array.Length; i++)
60 {
61 if (array[i] == "##local")
62 {
63 _set[string.Empty] = string.Empty;
64 continue;
65 }
66 if (array[i] == "##targetNamespace")
67 {
69 continue;
70 }
72 _set[array[i]] = array[i];
73 }
74 }
75
77 {
78 NamespaceList namespaceList = (NamespaceList)MemberwiseClone();
79 if (_type == ListType.Set)
80 {
82 }
83 return namespaceList;
84 }
85
86 public virtual bool Allows(string ns)
87 {
88 switch (_type)
89 {
90 case ListType.Any:
91 return true;
92 case ListType.Other:
93 if (ns != _targetNamespace)
94 {
95 return ns.Length != 0;
96 }
97 return false;
98 case ListType.Set:
99 return _set[ns] != null;
100 default:
101 return false;
102 }
103 }
104
105 public bool Allows(XmlQualifiedName qname)
106 {
107 return Allows(qname.Namespace);
108 }
109
110 public override string ToString()
111 {
112 switch (_type)
113 {
114 case ListType.Any:
115 return "##any";
116 case ListType.Other:
117 return "##other";
118 case ListType.Set:
119 {
121 bool flag = true;
122 foreach (string key in _set.Keys)
123 {
124 if (flag)
125 {
126 flag = false;
127 }
128 else
129 {
130 stringBuilder.Append(' ');
131 }
132 if (key == _targetNamespace)
133 {
134 stringBuilder.Append("##targetNamespace");
135 }
136 else if (key.Length == 0)
137 {
138 stringBuilder.Append("##local");
139 }
140 else
141 {
142 stringBuilder.Append(key);
143 }
144 }
145 return stringBuilder.ToString();
146 }
147 default:
148 return string.Empty;
149 }
150 }
151
153 {
154 if (super._type == ListType.Any)
155 {
156 return true;
157 }
158 if (sub._type == ListType.Other && super._type == ListType.Other)
159 {
160 return super._targetNamespace == sub._targetNamespace;
161 }
162 if (sub._type == ListType.Set)
163 {
164 if (super._type == ListType.Other)
165 {
166 return !sub._set.Contains(super._targetNamespace);
167 }
168 foreach (string key in sub._set.Keys)
169 {
170 if (!super._set.Contains(key))
171 {
172 return false;
173 }
174 }
175 return true;
176 }
177 return false;
178 }
179
181 {
182 NamespaceList namespaceList = null;
183 if (o1._type == ListType.Any)
184 {
185 namespaceList = new NamespaceList();
186 }
187 else if (o2._type == ListType.Any)
188 {
189 namespaceList = new NamespaceList();
190 }
191 else if (o1._type == ListType.Set && o2._type == ListType.Set)
192 {
193 namespaceList = o1.Clone();
194 foreach (string key in o2._set.Keys)
195 {
196 namespaceList._set[key] = key;
197 }
198 }
199 else if (o1._type == ListType.Other && o2._type == ListType.Other)
200 {
201 namespaceList = ((!(o1._targetNamespace == o2._targetNamespace)) ? new NamespaceList("##other", string.Empty) : o1.Clone());
202 }
203 else if (o1._type == ListType.Set && o2._type == ListType.Other)
204 {
205 namespaceList = (v1Compat ? ((!o1._set.Contains(o2._targetNamespace)) ? o2.Clone() : new NamespaceList()) : ((o2._targetNamespace != string.Empty) ? o1.CompareSetToOther(o2) : ((!o1._set.Contains(string.Empty)) ? new NamespaceList("##other", string.Empty) : new NamespaceList())));
206 }
207 else if (o2._type == ListType.Set && o1._type == ListType.Other)
208 {
209 namespaceList = (v1Compat ? ((!o2._set.Contains(o2._targetNamespace)) ? o1.Clone() : new NamespaceList()) : ((o1._targetNamespace != string.Empty) ? o2.CompareSetToOther(o1) : ((!o2._set.Contains(string.Empty)) ? new NamespaceList("##other", string.Empty) : new NamespaceList())));
210 }
211 return namespaceList;
212 }
213
215 {
216 NamespaceList namespaceList = null;
217 if (_set.Contains(other._targetNamespace))
218 {
219 if (_set.Contains(string.Empty))
220 {
221 return new NamespaceList();
222 }
223 return new NamespaceList("##other", string.Empty);
224 }
225 if (_set.Contains(string.Empty))
226 {
227 return null;
228 }
229 return other.Clone();
230 }
231
233 {
234 NamespaceList namespaceList = null;
235 if (o1._type == ListType.Any)
236 {
237 namespaceList = o2.Clone();
238 }
239 else if (o2._type == ListType.Any)
240 {
241 namespaceList = o1.Clone();
242 }
243 else if (o1._type == ListType.Set && o2._type == ListType.Other)
244 {
245 namespaceList = o1.Clone();
246 namespaceList.RemoveNamespace(o2._targetNamespace);
247 if (!v1Compat)
248 {
249 namespaceList.RemoveNamespace(string.Empty);
250 }
251 }
252 else if (o1._type == ListType.Other && o2._type == ListType.Set)
253 {
254 namespaceList = o2.Clone();
255 namespaceList.RemoveNamespace(o1._targetNamespace);
256 if (!v1Compat)
257 {
258 namespaceList.RemoveNamespace(string.Empty);
259 }
260 }
261 else if (o1._type == ListType.Set && o2._type == ListType.Set)
262 {
263 namespaceList = o1.Clone();
264 namespaceList = new NamespaceList();
267 foreach (string key in o1._set.Keys)
268 {
269 if (o2._set.Contains(key))
270 {
271 namespaceList._set.Add(key, key);
272 }
273 }
274 }
275 else if (o1._type == ListType.Other && o2._type == ListType.Other)
276 {
277 if (o1._targetNamespace == o2._targetNamespace)
278 {
279 return o1.Clone();
280 }
281 if (!v1Compat)
282 {
283 if (o1._targetNamespace == string.Empty)
284 {
285 namespaceList = o2.Clone();
286 }
287 else if (o2._targetNamespace == string.Empty)
288 {
289 namespaceList = o1.Clone();
290 }
291 }
292 }
293 return namespaceList;
294 }
295
296 private void RemoveNamespace(string tns)
297 {
298 if (_set[tns] != null)
299 {
300 _set.Remove(tns);
301 }
302 }
303}
virtual bool Contains(object key)
Definition Hashtable.cs:719
virtual void Remove(object key)
virtual ICollection Keys
Definition Hashtable.cs:532
virtual void Add(object key, object? value)
Definition Hashtable.cs:676
static bool IsSubset(NamespaceList sub, NamespaceList super)
static NamespaceList Intersection(NamespaceList o1, NamespaceList o2, bool v1Compat)
static NamespaceList Union(NamespaceList o1, NamespaceList o2, bool v1Compat)
NamespaceList CompareSetToOther(NamespaceList other)
NamespaceList(string namespaces, string targetNamespace)
virtual bool Allows(string ns)
bool Allows(XmlQualifiedName qname)
static string[] SplitString(string value)
static Uri ToUri(string s)