Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XsltLibrary.cs
Go to the documentation of this file.
8
10
12public sealed class XsltLibrary
13{
14 internal enum ComparisonOperator
15 {
16 Eq,
17 Ne,
18 Lt,
19 Le,
20 Gt,
21 Ge
22 }
23
24 private readonly XmlQueryRuntime _runtime;
25
27
29
31
36
37 public string FormatMessage(string res, IList<string> args)
38 {
39 string[] array = new string[args.Count];
40 for (int i = 0; i < array.Length; i++)
41 {
42 array[i] = args[i];
43 }
45 }
46
47 public int CheckScriptNamespace(string nsUri)
48 {
50 {
52 }
53 return 0;
54 }
55
57 {
59 }
60
61 [RequiresUnreferencedCode("The extension function referenced will be called from the stylesheet which cannot be statically analyzed.")]
63 {
64 if (_functionsAvail == null)
65 {
67 }
68 else
69 {
70 object obj = _functionsAvail[name];
71 if (obj != null)
72 {
73 return (bool)obj;
74 }
75 }
76 bool flag = FunctionAvailableHelper(name);
77 _functionsAvail[name] = flag;
78 return flag;
79 }
80
81 [RequiresUnreferencedCode("The extension function referenced will be called from the stylesheet which cannot be statically analyzed.")]
83 {
84 if (QilGenerator.IsFunctionAvailable(name.Name, name.Namespace))
85 {
86 return true;
87 }
88 if (name.Namespace.Length == 0 || name.Namespace == "http://www.w3.org/1999/XSL/Transform")
89 {
90 return false;
91 }
92 if (_runtime.ExternalContext.LateBoundFunctionExists(name.Name, name.Namespace))
93 {
94 return true;
95 }
96 return _runtime.EarlyBoundFunctionExists(name.Name, name.Namespace);
97 }
98
99 public int RegisterDecimalFormat(XmlQualifiedName name, string infinitySymbol, string nanSymbol, string characters)
100 {
101 if (_decimalFormats == null)
102 {
104 }
106 return 0;
107 }
108
109 private DecimalFormat CreateDecimalFormat(string infinitySymbol, string nanSymbol, string characters)
110 {
112 numberFormatInfo.NumberDecimalSeparator = char.ToString(characters[0]);
113 numberFormatInfo.NumberGroupSeparator = char.ToString(characters[1]);
115 numberFormatInfo.NegativeSign = char.ToString(characters[7]);
117 numberFormatInfo.PercentSymbol = char.ToString(characters[2]);
118 numberFormatInfo.PerMilleSymbol = char.ToString(characters[3]);
120 return new DecimalFormat(numberFormatInfo, characters[5], characters[4], characters[6]);
121 }
122
123 public double RegisterDecimalFormatter(string formatPicture, string infinitySymbol, string nanSymbol, string characters)
124 {
125 if (_decimalFormatters == null)
126 {
128 }
130 return _decimalFormatters.Count - 1;
131 }
132
133 public string FormatNumberStatic(double value, double decimalFormatterIndex)
134 {
135 int index = (int)decimalFormatterIndex;
136 return _decimalFormatters[index].Format(value);
137 }
138
148
149 public string NumberFormat(IList<XPathItem> value, string formatString, double lang, string letterValue, string groupingSeparator, double groupingSize)
150 {
152 return numberFormatter.FormatSequence(value);
153 }
154
155 public int LangToLcid(string lang, bool forwardCompatibility)
156 {
157 return LangToLcidInternal(lang, forwardCompatibility, null);
158 }
159
160 internal static int LangToLcidInternal(string lang, bool forwardCompatibility, IErrorHelper errorHelper)
161 {
162 int result = 127;
163 if (lang != null)
164 {
165 if (lang.Length == 0)
166 {
168 {
169 if (errorHelper == null)
170 {
171 throw new XslTransformException(System.SR.Xslt_InvalidAttrValue, "lang", lang);
172 }
173 errorHelper.ReportError(System.SR.Xslt_InvalidAttrValue, "lang", lang);
174 }
175 }
176 else
177 {
178 try
179 {
180 result = new CultureInfo(lang).LCID;
181 }
182 catch (ArgumentException)
183 {
185 {
186 if (errorHelper == null)
187 {
189 }
190 errorHelper.ReportError(System.SR.Xslt_InvalidLanguage, lang);
191 }
192 }
193 }
194 }
195 return result;
196 }
197
198 internal static string LangToNameInternal(string lang, bool forwardCompatibility, IErrorHelper errorHelper)
199 {
200 string result = "";
201 if (lang != null)
202 {
203 if (lang.Length == 0)
204 {
206 {
207 if (errorHelper == null)
208 {
209 throw new XslTransformException(System.SR.Xslt_InvalidAttrValue, "lang", lang);
210 }
211 errorHelper.ReportError(System.SR.Xslt_InvalidAttrValue, "lang", lang);
212 }
213 }
214 else
215 {
216 try
217 {
218 result = new CultureInfo(lang).Name;
219 }
220 catch (ArgumentException)
221 {
223 {
224 if (errorHelper == null)
225 {
227 }
228 errorHelper.ReportError(System.SR.Xslt_InvalidLanguage, lang);
229 }
230 }
231 }
232 }
233 return result;
234 }
235
237 {
238 Type valueType = item.ValueType;
240 {
241 return TypeCode.String;
242 }
244 {
245 return TypeCode.Double;
246 }
247 return TypeCode.Boolean;
248 }
249
251 {
252 if (typeCode1 >= typeCode2)
253 {
254 return typeCode2;
255 }
256 return typeCode1;
257 }
258
259 private static bool CompareNumbers(ComparisonOperator op, double left, double right)
260 {
261 return op switch
262 {
263 ComparisonOperator.Eq => left == right,
264 ComparisonOperator.Ne => left != right,
265 ComparisonOperator.Lt => left < right,
266 ComparisonOperator.Le => left <= right,
267 ComparisonOperator.Gt => left > right,
268 _ => left >= right,
269 };
270 }
271
273 {
274 return compType switch
275 {
278 _ => XsltConvert.ToBoolean(left) == XsltConvert.ToBoolean(right) == (op == ComparisonOperator.Eq),
279 };
280 }
281
283 {
284 if (compType == TypeCode.Boolean)
285 {
286 return CompareNumbers(op, (nodeset.Count != 0) ? 1 : 0, XsltConvert.ToBoolean(val) ? 1 : 0);
287 }
288 int count = nodeset.Count;
289 for (int i = 0; i < count; i++)
290 {
291 if (CompareValues(op, nodeset[i], val, compType))
292 {
293 return true;
294 }
295 }
296 return false;
297 }
298
300 {
301 int count = left.Count;
302 int count2 = right.Count;
303 for (int i = 0; i < count; i++)
304 {
305 for (int j = 0; j < count2; j++)
306 {
307 if (CompareValues(op, left[i], right[j], compType))
308 {
309 return true;
310 }
311 }
312 }
313 return false;
314 }
315
317 {
319 if (IsNodeSetOrRtf(left))
320 {
321 if (IsNodeSetOrRtf(right))
322 {
324 }
325 XPathItem xPathItem = right[0];
327 }
328 if (IsNodeSetOrRtf(right))
329 {
330 XPathItem xPathItem2 = left[0];
332 }
333 XPathItem xPathItem3 = left[0];
334 XPathItem xPathItem4 = right[0];
336 }
337
349
351 {
353 if (IsNodeSetOrRtf(left))
354 {
355 if (IsNodeSetOrRtf(right))
356 {
358 }
359 XPathItem xPathItem = right[0];
361 }
362 if (IsNodeSetOrRtf(right))
363 {
364 XPathItem xPathItem2 = left[0];
367 }
368 XPathItem left2 = left[0];
369 XPathItem right2 = right[0];
370 return CompareValues(op, left2, right2, TypeCode.Double);
371 }
372
374 {
375 XPathNodeType nodeType = nav1.NodeType;
376 XPathNodeType nodeType2 = nav2.NodeType;
377 if (XPathNodeType.Text <= nodeType && nodeType <= XPathNodeType.Whitespace)
378 {
379 if (XPathNodeType.Text <= nodeType2)
380 {
381 return nodeType2 <= XPathNodeType.Whitespace;
382 }
383 return false;
384 }
385 if (nodeType == nodeType2 && Ref.Equal(nav1.LocalName, nav2.LocalName))
386 {
387 return Ref.Equal(nav1.NamespaceURI, nav2.NamespaceURI);
388 }
389 return false;
390 }
391
392 private static bool IsNodeSetOrRtf(IList<XPathItem> val)
393 {
394 if (val.Count == 1)
395 {
396 return val[0].IsNode;
397 }
398 return true;
399 }
400
405}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void Add(TKey key, TValue value)
static string Xslt_ScriptAndExtensionClash
Definition SR.cs:1934
static string Xslt_InvalidAttrValue
Definition SR.cs:1884
static string Xslt_InvalidLanguage
Definition SR.cs:1974
static string Xslt_NoDecimalFormat
Definition SR.cs:1936
Definition SR.cs:7
static bool Equal(string strA, string strB)
Definition Ref.cs:5
static IList< XPathNavigator > ItemsToNavigators(IList< XPathItem > listItems)
bool LateBoundFunctionExists(string name, string namespaceUri)
object GetLateBoundObject(string namespaceUri)
bool EarlyBoundFunctionExists(string name, string namespaceUri)
static readonly Type StringType
static bool ToBoolean(XPathItem item)
static readonly Type DoubleType
static double ToDouble(string value)
static string ToString(double value)
string FormatMessage(string res, IList< string > args)
static bool CompareNodeSetAndNodeSet(ComparisonOperator op, IList< XPathNavigator > left, IList< XPathNavigator > right, TypeCode compType)
string FormatNumberDynamic(double value, string formatPicture, XmlQualifiedName decimalFormatName, string errorMessageName)
static ComparisonOperator InvertOperator(ComparisonOperator op)
bool EqualityOperator(double opCode, IList< XPathItem > left, IList< XPathItem > right)
Dictionary< XmlQualifiedName, DecimalFormat > _decimalFormats
bool RelationalOperator(double opCode, IList< XPathItem > left, IList< XPathItem > right)
readonly XmlQueryRuntime _runtime
List< DecimalFormatter > _decimalFormatters
static IList< XPathNavigator > ToNodeSetOrRtf(IList< XPathItem > val)
int LangToLcid(string lang, bool forwardCompatibility)
bool FunctionAvailableHelper(XmlQualifiedName name)
XsltLibrary(XmlQueryRuntime runtime)
static TypeCode GetTypeCode(XPathItem item)
static string LangToNameInternal(string lang, bool forwardCompatibility, IErrorHelper errorHelper)
string FormatNumberStatic(double value, double decimalFormatterIndex)
static bool CompareNumbers(ComparisonOperator op, double left, double right)
bool IsSameNodeSort(XPathNavigator nav1, XPathNavigator nav2)
static int LangToLcidInternal(string lang, bool forwardCompatibility, IErrorHelper errorHelper)
bool FunctionAvailable(XmlQualifiedName name)
string NumberFormat(IList< XPathItem > value, string formatString, double lang, string letterValue, string groupingSeparator, double groupingSize)
static TypeCode WeakestTypeCode(TypeCode typeCode1, TypeCode typeCode2)
double RegisterDecimalFormatter(string formatPicture, string infinitySymbol, string nanSymbol, string characters)
DecimalFormat CreateDecimalFormat(string infinitySymbol, string nanSymbol, string characters)
bool ElementAvailable(XmlQualifiedName name)
static bool IsNodeSetOrRtf(IList< XPathItem > val)
static bool CompareNodeSetAndValue(ComparisonOperator op, IList< XPathNavigator > nodeset, XPathItem val, TypeCode compType)
int RegisterDecimalFormat(XmlQualifiedName name, string infinitySymbol, string nanSymbol, string characters)
static bool CompareValues(ComparisonOperator op, XPathItem left, XPathItem right, TypeCode compType)
int CheckScriptNamespace(string nsUri)
static string CreateMessage(string res, params string[] args)
static bool IsElementAvailable(XmlQualifiedName name)
static bool IsFunctionAvailable(string localName, string nsUri)
TypeCode
Definition TypeCode.cs:4