Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FilterQuery.cs
Go to the documentation of this file.
3
5
6internal sealed class FilterQuery : BaseAxisQuery
7{
8 private readonly Query _cond;
9
10 private readonly bool _noPosition;
11
13
14 public override QueryProps Properties => QueryProps.Position | (qyInput.Properties & (QueryProps)24);
15
16 public FilterQuery(Query qyParent, Query cond, bool noPosition)
17 : base(qyParent)
18 {
19 _cond = cond;
20 _noPosition = noPosition;
21 }
22
23 private FilterQuery(FilterQuery other)
24 : base(other)
25 {
26 _cond = Query.Clone(other._cond);
27 _noPosition = other._noPosition;
28 }
29
30 public override void Reset()
31 {
32 _cond.Reset();
33 base.Reset();
34 }
35
36 public override void SetXsltContext(XsltContext input)
37 {
38 base.SetXsltContext(input);
39 _cond.SetXsltContext(input);
40 if (_cond.StaticType != 0 && _cond.StaticType != XPathResultType.Any && _noPosition && qyInput is ReversePositionQuery reversePositionQuery)
41 {
42 qyInput = reversePositionQuery.input;
43 }
44 }
45
46 public override XPathNavigator Advance()
47 {
48 while ((currentNode = qyInput.Advance()) != null)
49 {
51 {
52 position++;
53 return currentNode;
54 }
55 }
56 return null;
57 }
58
59 internal bool EvaluatePredicate()
60 {
61 object obj = _cond.Evaluate(qyInput);
62 if (obj is XPathNodeIterator)
63 {
64 return _cond.Advance() != null;
65 }
66 if (obj is string)
67 {
68 return ((string)obj).Length != 0;
69 }
70 if (obj is double)
71 {
72 return (double)obj == (double)qyInput.CurrentPosition;
73 }
74 if (obj is bool)
75 {
76 return (bool)obj;
77 }
78 return true;
79 }
80
81 public override XPathNavigator MatchNode(XPathNavigator current)
82 {
83 if (current == null)
84 {
85 return null;
86 }
87 XPathNavigator xPathNavigator = qyInput.MatchNode(current);
88 if (xPathNavigator != null)
89 {
90 switch (_cond.StaticType)
91 {
92 case XPathResultType.Number:
93 {
94 if (!(_cond is OperandQuery operandQuery))
95 {
96 break;
97 }
98 double num = (double)operandQuery.val;
99 if (qyInput is ChildrenQuery childrenQuery)
100 {
101 XPathNavigator xPathNavigator2 = current.Clone();
102 xPathNavigator2.MoveToParent();
103 int num2 = 0;
104 xPathNavigator2.MoveToFirstChild();
105 do
106 {
107 if (!childrenQuery.matches(xPathNavigator2))
108 {
109 continue;
110 }
111 num2++;
112 if (current.IsSamePosition(xPathNavigator2))
113 {
114 if (num != (double)num2)
115 {
116 return null;
117 }
118 return xPathNavigator;
119 }
120 }
121 while (xPathNavigator2.MoveToNext());
122 return null;
123 }
124 if (!(qyInput is AttributeQuery attributeQuery))
125 {
126 break;
127 }
128 XPathNavigator xPathNavigator3 = current.Clone();
129 xPathNavigator3.MoveToParent();
130 int num3 = 0;
131 xPathNavigator3.MoveToFirstAttribute();
132 do
133 {
134 if (!attributeQuery.matches(xPathNavigator3))
135 {
136 continue;
137 }
138 num3++;
139 if (current.IsSamePosition(xPathNavigator3))
140 {
141 if (num != (double)num3)
142 {
143 return null;
144 }
145 return xPathNavigator;
146 }
147 }
148 while (xPathNavigator3.MoveToNextAttribute());
149 return null;
150 }
151 case XPathResultType.NodeSet:
152 _cond.Evaluate(new XPathSingletonIterator(current, moved: true));
153 if (_cond.Advance() == null)
154 {
155 return null;
156 }
157 return xPathNavigator;
158 case XPathResultType.Boolean:
159 if (_noPosition)
160 {
161 if (!(bool)_cond.Evaluate(new XPathSingletonIterator(current, moved: true)))
162 {
163 return null;
164 }
165 return xPathNavigator;
166 }
167 break;
168 case XPathResultType.String:
169 if (_noPosition)
170 {
171 if (((string)_cond.Evaluate(new XPathSingletonIterator(current, moved: true))).Length == 0)
172 {
173 return null;
174 }
175 return xPathNavigator;
176 }
177 break;
178 case (XPathResultType)4:
179 return xPathNavigator;
180 default:
181 return null;
182 }
183 Evaluate(new XPathSingletonIterator(xPathNavigator, moved: true));
184 XPathNavigator xPathNavigator4;
185 while ((xPathNavigator4 = Advance()) != null)
186 {
187 if (xPathNavigator4.IsSamePosition(current))
188 {
189 return xPathNavigator;
190 }
191 }
192 }
193 return null;
194 }
195
196 public override XPathNodeIterator Clone()
197 {
198 return new FilterQuery(this);
199 }
200}
override object Evaluate(XPathNodeIterator nodeIterator)
override void SetXsltContext(XsltContext input)
FilterQuery(Query qyParent, Query cond, bool noPosition)
override XPathNodeIterator Clone()
override QueryProps Properties
override XPathNavigator Advance()
override XPathNavigator MatchNode(XPathNavigator current)
object Evaluate(XPathNodeIterator nodeIterator)
virtual void SetXsltContext(XsltContext context)
Definition Query.cs:52
virtual XPathNavigator MatchNode(XPathNavigator current)
Definition Query.cs:60
XPathNavigator Advance()
XPathResultType StaticType
Definition Query.cs:34
static Query Clone(Query input)
Definition Query.cs:66
bool IsSamePosition(XPathNavigator other)