Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XPathNodeHelper.cs
Go to the documentation of this file.
2
4
5internal abstract class XPathNodeHelper
6{
7 public static int GetLocalNamespaces(XPathNode[] pageElem, int idxElem, out XPathNode[] pageNmsp)
8 {
9 if (pageElem[idxElem].HasNamespaceDecls)
10 {
11 return pageElem[idxElem].Document.LookupNamespaces(pageElem, idxElem, out pageNmsp);
12 }
13 pageNmsp = null;
14 return 0;
15 }
16
17 public static int GetInScopeNamespaces(XPathNode[] pageElem, int idxElem, out XPathNode[] pageNmsp)
18 {
19 if (pageElem[idxElem].NodeType == XPathNodeType.Element)
20 {
21 XPathDocument document = pageElem[idxElem].Document;
22 while (!pageElem[idxElem].HasNamespaceDecls)
23 {
24 idxElem = pageElem[idxElem].GetParent(out pageElem);
25 if (idxElem == 0)
26 {
27 return document.GetXmlNamespaceNode(out pageNmsp);
28 }
29 }
30 return document.LookupNamespaces(pageElem, idxElem, out pageNmsp);
31 }
32 pageNmsp = null;
33 return 0;
34 }
35
36 public static bool GetFirstAttribute(ref XPathNode[] pageNode, ref int idxNode)
37 {
38 if (pageNode[idxNode].HasAttribute)
39 {
40 GetChild(ref pageNode, ref idxNode);
41 return true;
42 }
43 return false;
44 }
45
46 public static bool GetNextAttribute(ref XPathNode[] pageNode, ref int idxNode)
47 {
48 XPathNode[] pageNode2;
49 int sibling = pageNode[idxNode].GetSibling(out pageNode2);
50 if (sibling != 0 && pageNode2[sibling].NodeType == XPathNodeType.Attribute)
51 {
52 pageNode = pageNode2;
53 idxNode = sibling;
54 return true;
55 }
56 return false;
57 }
58
59 public static bool GetContentChild(ref XPathNode[] pageNode, ref int idxNode)
60 {
61 XPathNode[] pageNode2 = pageNode;
62 int idxNode2 = idxNode;
63 if (pageNode2[idxNode2].HasContentChild)
64 {
65 GetChild(ref pageNode2, ref idxNode2);
66 while (pageNode2[idxNode2].NodeType == XPathNodeType.Attribute)
67 {
68 idxNode2 = pageNode2[idxNode2].GetSibling(out pageNode2);
69 }
70 pageNode = pageNode2;
71 idxNode = idxNode2;
72 return true;
73 }
74 return false;
75 }
76
77 public static bool GetContentSibling(ref XPathNode[] pageNode, ref int idxNode)
78 {
79 XPathNode[] pageNode2 = pageNode;
80 int num = idxNode;
81 if (!pageNode2[num].IsAttrNmsp)
82 {
83 num = pageNode2[num].GetSibling(out pageNode2);
84 if (num != 0)
85 {
86 pageNode = pageNode2;
87 idxNode = num;
88 return true;
89 }
90 }
91 return false;
92 }
93
94 public static bool GetParent(ref XPathNode[] pageNode, ref int idxNode)
95 {
96 XPathNode[] pageNode2 = pageNode;
97 int num = idxNode;
98 num = pageNode2[num].GetParent(out pageNode2);
99 if (num != 0)
100 {
101 pageNode = pageNode2;
102 idxNode = num;
103 return true;
104 }
105 return false;
106 }
107
108 public static int GetLocation(XPathNode[] pageNode, int idxNode)
109 {
110 return (pageNode[0].PageInfo.PageNumber << 16) | idxNode;
111 }
112
113 public static bool GetElementChild(ref XPathNode[] pageNode, ref int idxNode, string localName, string namespaceName)
114 {
115 XPathNode[] pageNode2 = pageNode;
116 int idxNode2 = idxNode;
117 if (pageNode2[idxNode2].HasElementChild)
118 {
119 GetChild(ref pageNode2, ref idxNode2);
120 do
121 {
122 if (pageNode2[idxNode2].ElementMatch(localName, namespaceName))
123 {
124 pageNode = pageNode2;
125 idxNode = idxNode2;
126 return true;
127 }
128 idxNode2 = pageNode2[idxNode2].GetSibling(out pageNode2);
129 }
130 while (idxNode2 != 0);
131 }
132 return false;
133 }
134
135 public static bool GetElementSibling(ref XPathNode[] pageNode, ref int idxNode, string localName, string namespaceName)
136 {
137 XPathNode[] pageNode2 = pageNode;
138 int num = idxNode;
139 if (pageNode2[num].NodeType != XPathNodeType.Attribute)
140 {
141 while (true)
142 {
143 num = pageNode2[num].GetSibling(out pageNode2);
144 if (num == 0)
145 {
146 break;
147 }
148 if (pageNode2[num].ElementMatch(localName, namespaceName))
149 {
150 pageNode = pageNode2;
151 idxNode = num;
152 return true;
153 }
154 }
155 }
156 return false;
157 }
158
159 public static bool GetContentChild(ref XPathNode[] pageNode, ref int idxNode, XPathNodeType typ)
160 {
161 XPathNode[] pageNode2 = pageNode;
162 int idxNode2 = idxNode;
163 if (pageNode2[idxNode2].HasContentChild)
164 {
165 int contentKindMask = XPathNavigator.GetContentKindMask(typ);
166 GetChild(ref pageNode2, ref idxNode2);
167 do
168 {
169 if (((1 << (int)pageNode2[idxNode2].NodeType) & contentKindMask) != 0)
170 {
171 if (typ == XPathNodeType.Attribute)
172 {
173 return false;
174 }
175 pageNode = pageNode2;
176 idxNode = idxNode2;
177 return true;
178 }
179 idxNode2 = pageNode2[idxNode2].GetSibling(out pageNode2);
180 }
181 while (idxNode2 != 0);
182 }
183 return false;
184 }
185
186 public static bool GetContentSibling(ref XPathNode[] pageNode, ref int idxNode, XPathNodeType typ)
187 {
188 XPathNode[] pageNode2 = pageNode;
189 int num = idxNode;
190 int contentKindMask = XPathNavigator.GetContentKindMask(typ);
191 if (pageNode2[num].NodeType != XPathNodeType.Attribute)
192 {
193 while (true)
194 {
195 num = pageNode2[num].GetSibling(out pageNode2);
196 if (num == 0)
197 {
198 break;
199 }
200 if (((1 << (int)pageNode2[num].NodeType) & contentKindMask) != 0)
201 {
202 pageNode = pageNode2;
203 idxNode = num;
204 return true;
205 }
206 }
207 }
208 return false;
209 }
210
211 public static bool GetPreviousContentSibling(ref XPathNode[] pageNode, ref int idxNode)
212 {
213 int num = idxNode;
214 num = pageNode[num].GetParent(out var pageNode2);
215 if (num != 0)
216 {
217 int num2 = idxNode - 1;
218 XPathNode[] array;
219 if (num2 == 0)
220 {
221 array = pageNode[0].PageInfo.PreviousPage;
222 num2 = array.Length - 1;
223 }
224 else
225 {
226 array = pageNode;
227 }
228 if (num == num2 && pageNode2 == array)
229 {
230 return false;
231 }
232 XPathNode[] pageNode3 = array;
233 int num3 = num2;
234 do
235 {
236 array = pageNode3;
237 num2 = num3;
238 num3 = pageNode3[num3].GetParent(out pageNode3);
239 }
240 while (num3 != num || pageNode3 != pageNode2);
241 if (array[num2].NodeType != XPathNodeType.Attribute)
242 {
243 pageNode = array;
244 idxNode = num2;
245 return true;
246 }
247 }
248 return false;
249 }
250
251 public static bool GetAttribute(ref XPathNode[] pageNode, ref int idxNode, string localName, string namespaceName)
252 {
253 XPathNode[] pageNode2 = pageNode;
254 int idxNode2 = idxNode;
255 if (pageNode2[idxNode2].HasAttribute)
256 {
257 GetChild(ref pageNode2, ref idxNode2);
258 do
259 {
260 if (pageNode2[idxNode2].NameMatch(localName, namespaceName))
261 {
262 pageNode = pageNode2;
263 idxNode = idxNode2;
264 return true;
265 }
266 idxNode2 = pageNode2[idxNode2].GetSibling(out pageNode2);
267 }
268 while (idxNode2 != 0 && pageNode2[idxNode2].NodeType == XPathNodeType.Attribute);
269 }
270 return false;
271 }
272
273 public static bool GetElementFollowing(ref XPathNode[] pageCurrent, ref int idxCurrent, XPathNode[] pageEnd, int idxEnd, string localName, string namespaceName)
274 {
275 XPathNode[] pageNode = pageCurrent;
276 int i = idxCurrent;
277 if (pageNode[i].NodeType == XPathNodeType.Element && (object)pageNode[i].LocalName == localName)
278 {
279 int num = 0;
280 if (pageEnd != null)
281 {
282 num = pageEnd[0].PageInfo.PageNumber;
283 int pageNumber = pageNode[0].PageInfo.PageNumber;
284 if (pageNumber > num || (pageNumber == num && i >= idxEnd))
285 {
286 pageEnd = null;
287 }
288 }
289 while (true)
290 {
291 i = pageNode[i].GetSimilarElement(out pageNode);
292 if (i != 0)
293 {
294 if (pageEnd != null)
295 {
296 int pageNumber = pageNode[0].PageInfo.PageNumber;
297 if (pageNumber > num || (pageNumber == num && i >= idxEnd))
298 {
299 goto IL_00bd;
300 }
301 }
302 if ((object)pageNode[i].LocalName == localName && pageNode[i].NamespaceUri == namespaceName)
303 {
304 break;
305 }
306 continue;
307 }
308 goto IL_00bd;
309 IL_00bd:
310 return false;
311 }
312 }
313 else
314 {
315 i++;
316 while (true)
317 {
318 if (pageNode == pageEnd && i <= idxEnd)
319 {
320 for (; i != idxEnd; i++)
321 {
322 if (pageNode[i].ElementMatch(localName, namespaceName))
323 {
324 goto end_IL_00c3;
325 }
326 }
327 }
328 else
329 {
330 for (; i < pageNode[0].PageInfo.NodeCount; i++)
331 {
332 if (pageNode[i].ElementMatch(localName, namespaceName))
333 {
334 goto end_IL_00c3;
335 }
336 }
337 pageNode = pageNode[0].PageInfo.NextPage;
338 i = 1;
339 if (pageNode != null)
340 {
341 continue;
342 }
343 }
344 return false;
345 continue;
346 end_IL_00c3:
347 break;
348 }
349 }
350 pageCurrent = pageNode;
351 idxCurrent = i;
352 return true;
353 }
354
355 public static bool GetContentFollowing(ref XPathNode[] pageCurrent, ref int idxCurrent, XPathNode[] pageEnd, int idxEnd, XPathNodeType typ)
356 {
357 XPathNode[] array = pageCurrent;
358 int num = idxCurrent;
359 int contentKindMask = XPathNavigator.GetContentKindMask(typ);
360 num++;
361 while (true)
362 {
363 if (array == pageEnd && num <= idxEnd)
364 {
365 for (; num != idxEnd; num++)
366 {
367 if (((1 << (int)array[num].NodeType) & contentKindMask) != 0)
368 {
369 goto end_IL_0012;
370 }
371 }
372 }
373 else
374 {
375 for (; num < array[0].PageInfo.NodeCount; num++)
376 {
377 if (((1 << (int)array[num].NodeType) & contentKindMask) != 0)
378 {
379 goto end_IL_0012;
380 }
381 }
382 array = array[0].PageInfo.NextPage;
383 num = 1;
384 if (array != null)
385 {
386 continue;
387 }
388 }
389 return false;
390 continue;
391 end_IL_0012:
392 break;
393 }
394 pageCurrent = array;
395 idxCurrent = num;
396 return true;
397 }
398
399 public static bool GetTextFollowing(ref XPathNode[] pageCurrent, ref int idxCurrent, XPathNode[] pageEnd, int idxEnd)
400 {
401 XPathNode[] array = pageCurrent;
402 int num = idxCurrent;
403 num++;
404 while (true)
405 {
406 if (array == pageEnd && num <= idxEnd)
407 {
408 for (; num != idxEnd; num++)
409 {
410 if (array[num].IsText || (array[num].NodeType == XPathNodeType.Element && array[num].HasCollapsedText))
411 {
412 goto end_IL_000a;
413 }
414 }
415 }
416 else
417 {
418 for (; num < array[0].PageInfo.NodeCount; num++)
419 {
420 if (array[num].IsText || (array[num].NodeType == XPathNodeType.Element && array[num].HasCollapsedText))
421 {
422 goto end_IL_000a;
423 }
424 }
425 array = array[0].PageInfo.NextPage;
426 num = 1;
427 if (array != null)
428 {
429 continue;
430 }
431 }
432 return false;
433 continue;
434 end_IL_000a:
435 break;
436 }
437 pageCurrent = array;
438 idxCurrent = num;
439 return true;
440 }
441
442 public static bool GetNonDescendant(ref XPathNode[] pageNode, ref int idxNode)
443 {
444 XPathNode[] pageNode2 = pageNode;
445 int num = idxNode;
446 do
447 {
448 if (pageNode2[num].HasSibling)
449 {
450 pageNode = pageNode2;
451 idxNode = pageNode2[num].GetSibling(out pageNode);
452 return true;
453 }
454 num = pageNode2[num].GetParent(out pageNode2);
455 }
456 while (num != 0);
457 return false;
458 }
459
460 private static void GetChild(ref XPathNode[] pageNode, ref int idxNode)
461 {
462 if (++idxNode >= pageNode.Length)
463 {
464 pageNode = pageNode[0].PageInfo.NextPage;
465 idxNode = 1;
466 }
467 }
468}
static bool GetNextAttribute(ref XPathNode[] pageNode, ref int idxNode)
static bool GetElementSibling(ref XPathNode[] pageNode, ref int idxNode, string localName, string namespaceName)
static bool GetTextFollowing(ref XPathNode[] pageCurrent, ref int idxCurrent, XPathNode[] pageEnd, int idxEnd)
static int GetInScopeNamespaces(XPathNode[] pageElem, int idxElem, out XPathNode[] pageNmsp)
static bool GetPreviousContentSibling(ref XPathNode[] pageNode, ref int idxNode)
static int GetLocalNamespaces(XPathNode[] pageElem, int idxElem, out XPathNode[] pageNmsp)
static bool GetContentChild(ref XPathNode[] pageNode, ref int idxNode, XPathNodeType typ)
static bool GetFirstAttribute(ref XPathNode[] pageNode, ref int idxNode)
static bool GetContentSibling(ref XPathNode[] pageNode, ref int idxNode, XPathNodeType typ)
static bool GetElementChild(ref XPathNode[] pageNode, ref int idxNode, string localName, string namespaceName)
static bool GetContentFollowing(ref XPathNode[] pageCurrent, ref int idxCurrent, XPathNode[] pageEnd, int idxEnd, XPathNodeType typ)
static bool GetContentChild(ref XPathNode[] pageNode, ref int idxNode)
static bool GetNonDescendant(ref XPathNode[] pageNode, ref int idxNode)
static bool GetElementFollowing(ref XPathNode[] pageCurrent, ref int idxCurrent, XPathNode[] pageEnd, int idxEnd, string localName, string namespaceName)
static bool GetContentSibling(ref XPathNode[] pageNode, ref int idxNode)
static int GetLocation(XPathNode[] pageNode, int idxNode)
static bool GetParent(ref XPathNode[] pageNode, ref int idxNode)
static bool GetAttribute(ref XPathNode[] pageNode, ref int idxNode, string localName, string namespaceName)
static void GetChild(ref XPathNode[] pageNode, ref int idxNode)
int LookupNamespaces(XPathNode[] pageElem, int idxElem, out XPathNode[] pageNmsp)
int GetXmlNamespaceNode(out XPathNode[] pageXmlNmsp)
static int GetContentKindMask(XPathNodeType type)
XPathNodePageInfo PageInfo
Definition XPathNode.cs:51
int GetParent(out XPathNode[] pageNode)
Definition XPathNode.cs:121
int GetSibling(out XPathNode[] pageNode)
Definition XPathNode.cs:127
int GetSimilarElement(out XPathNode[] pageNode)
Definition XPathNode.cs:133