Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NumberAction.cs
Go to the documentation of this file.
5using System.Text;
8
10
12{
13 internal sealed class FormatInfo
14 {
15 public bool isSeparator;
16
18
19 public int length;
20
21 public string formatString;
22
28
29 public FormatInfo()
30 {
31 }
32 }
33
34 private sealed class NumberingFormat : NumberFormatterBase
35 {
37
38 private int _cMinLen;
39
40 private string _separator;
41
42 private int _sizeGroup;
43
44 internal NumberingFormat()
45 {
46 }
47
49 {
50 _seq = seq;
51 }
52
53 internal void setMinLen(int cMinLen)
54 {
56 }
57
58 internal void setGroupingSeparator(string separator)
59 {
61 }
62
63 internal void setGroupingSize(int sizeGroup)
64 {
65 if (0 <= sizeGroup && sizeGroup <= 9)
66 {
68 }
69 }
70
71 internal string FormatItem(object value)
72 {
73 double num;
74 if (value is int)
75 {
76 num = (int)value;
77 }
78 else
79 {
81 if (!(0.5 <= num) || double.IsPositiveInfinity(num))
82 {
84 }
85 num = XmlConvert.XPathRound(num);
86 }
87 switch (_seq)
88 {
89 case NumberingSequence.FirstAlpha:
90 case NumberingSequence.LCLetter:
91 if (num <= 2147483647.0)
92 {
95 return stringBuilder2.ToString();
96 }
97 break;
98 case NumberingSequence.FirstSpecial:
99 case NumberingSequence.LCRoman:
100 if (num <= 32767.0)
101 {
104 return stringBuilder.ToString();
105 }
106 break;
107 }
109 }
110
111 private static string ConvertToArabic(double val, int minLength, int groupSize, string groupSeparator)
112 {
113 string text;
114 if (groupSize != 0 && groupSeparator != null)
115 {
119 if (Math.Floor(val) == val)
120 {
122 }
123 text = val.ToString("N", numberFormatInfo);
124 }
125 else
126 {
127 text = val.ToString(CultureInfo.InvariantCulture);
128 }
129 return text.PadLeft(minLength, '0');
130 }
131 }
132
133 private static readonly FormatInfo s_defaultFormat = new FormatInfo(isSeparator: false, "0");
134
135 private static readonly FormatInfo s_defaultSeparator = new FormatInfo(isSeparator: true, ".");
136
137 private string _level;
138
139 private string _countPattern;
140
141 private int _countKey = -1;
142
143 private string _from;
144
145 private int _fromKey = -1;
146
147 private string _value;
148
149 private int _valueKey = -1;
150
152
153 private Avt _langAvt;
154
156
158
160
162
163 private string _lang;
164
165 private string _letter;
166
167 private string _groupingSep;
168
169 private string _groupingSize;
170
172
173 internal override bool CompileAttribute(Compiler compiler)
174 {
175 string localName = compiler.Input.LocalName;
176 string value = compiler.Input.Value;
177 if (Ref.Equal(localName, compiler.Atoms.Level))
178 {
179 if (value != "any" && value != "multiple" && value != "single")
180 {
182 }
183 _level = value;
184 }
185 else if (Ref.Equal(localName, compiler.Atoms.Count))
186 {
188 _countKey = compiler.AddQuery(value, allowVar: true, allowKey: true, isPattern: true);
189 }
190 else if (Ref.Equal(localName, compiler.Atoms.From))
191 {
192 _from = value;
193 _fromKey = compiler.AddQuery(value, allowVar: true, allowKey: true, isPattern: true);
194 }
195 else if (Ref.Equal(localName, compiler.Atoms.Value))
196 {
197 _value = value;
198 _valueKey = compiler.AddQuery(value);
199 }
200 else if (Ref.Equal(localName, compiler.Atoms.Format))
201 {
203 }
204 else if (Ref.Equal(localName, compiler.Atoms.Lang))
205 {
207 }
208 else if (Ref.Equal(localName, compiler.Atoms.LetterValue))
209 {
211 }
212 else if (Ref.Equal(localName, compiler.Atoms.GroupingSeparator))
213 {
215 }
216 else
217 {
218 if (!Ref.Equal(localName, compiler.Atoms.GroupingSize))
219 {
220 return false;
221 }
223 }
224 return true;
225 }
226
242
244 {
245 int num = 0;
247 if (xPathNavigator.NodeType == XPathNodeType.Attribute || xPathNavigator.NodeType == XPathNodeType.Namespace)
248 {
250 xPathNavigator.MoveToParent();
251 }
253 if (_fromKey != -1)
254 {
255 bool flag = false;
256 do
257 {
258 if (processor.Matches(xPathNavigator2, _fromKey))
259 {
260 flag = true;
261 break;
262 }
263 }
264 while (xPathNavigator2.MoveToParent());
265 XPathNodeIterator xPathNodeIterator = xPathNavigator2.SelectDescendants(XPathNodeType.All, matchSelf: true);
266 while (xPathNodeIterator.MoveNext())
267 {
268 if (processor.Matches(xPathNodeIterator.Current, _fromKey))
269 {
270 flag = true;
271 num = 0;
272 }
273 else if (MatchCountKey(processor, frame.Node, xPathNodeIterator.Current))
274 {
275 num++;
276 }
277 if (xPathNodeIterator.Current.IsSamePosition(xPathNavigator))
278 {
279 break;
280 }
281 }
282 if (!flag)
283 {
284 num = 0;
285 }
286 }
287 else
288 {
289 xPathNavigator2.MoveToRoot();
290 XPathNodeIterator xPathNodeIterator2 = xPathNavigator2.SelectDescendants(XPathNodeType.All, matchSelf: true);
291 while (xPathNodeIterator2.MoveNext())
292 {
293 if (MatchCountKey(processor, frame.Node, xPathNodeIterator2.Current))
294 {
295 num++;
296 }
297 if (xPathNodeIterator2.Current.IsSamePosition(xPathNavigator))
298 {
299 break;
300 }
301 }
302 }
303 return num;
304 }
305
307 {
308 if (_fromKey == -1)
309 {
310 return true;
311 }
312 do
313 {
314 if (processor.Matches(nav, _fromKey))
315 {
316 return true;
317 }
318 }
319 while (nav.MoveToParent());
320 return false;
321 }
322
324 {
325 do
326 {
327 if (_fromKey != -1 && processor.Matches(nav, _fromKey))
328 {
329 return false;
330 }
331 if (MatchCountKey(processor, contextNode, nav))
332 {
333 return true;
334 }
335 }
336 while (nav.MoveToParent());
337 return false;
338 }
339
341 {
343 int num = 1;
344 if (xPathNavigator.MoveToParent())
345 {
346 xPathNavigator.MoveToFirstChild();
347 while (!xPathNavigator.IsSamePosition(nav))
348 {
349 if (MatchCountKey(processor, contextNode, xPathNavigator))
350 {
351 num++;
352 }
353 if (!xPathNavigator.MoveToNext())
354 {
355 break;
356 }
357 }
358 }
359 return num;
360 }
361
362 private static object SimplifyValue(object value)
363 {
364 if (Type.GetTypeCode(value.GetType()) == TypeCode.Object)
365 {
367 {
368 if (xPathNodeIterator.MoveNext())
369 {
370 return xPathNodeIterator.Current.Value;
371 }
372 return string.Empty;
373 }
375 {
376 return xPathNavigator.Value;
377 }
378 }
379 return value;
380 }
381
382 internal override void Execute(Processor processor, ActionFrame frame)
383 {
384 ArrayList numberList = processor.NumberList;
385 switch (frame.State)
386 {
387 default:
388 return;
389 case 0:
391 if (_valueKey != -1)
392 {
394 }
395 else if (_level == "any")
396 {
397 int num = numberAny(processor, frame);
398 if (num != 0)
399 {
400 numberList.Add(num);
401 }
402 }
403 else
404 {
405 bool flag = _level == "multiple";
406 XPathNavigator node = frame.Node;
408 if (xPathNavigator.NodeType == XPathNodeType.Attribute || xPathNavigator.NodeType == XPathNodeType.Namespace)
409 {
410 xPathNavigator.MoveToParent();
411 }
413 {
415 if (!flag || !xPathNavigator.MoveToParent())
416 {
417 break;
418 }
419 }
421 {
423 }
424 }
426 break;
427 case 2:
428 break;
429 }
430 if (!processor.TextEvent(frame.StoredOutput))
431 {
432 frame.State = 2;
433 }
434 else
435 {
436 frame.Finished();
437 }
438 }
439
441 {
442 if (_countKey != -1)
443 {
444 return processor.Matches(nav, _countKey);
445 }
446 if (contextNode.Name == nav.Name && BasicNodeType(contextNode.NodeType) == BasicNodeType(nav.NodeType))
447 {
448 return true;
449 }
450 return false;
451 }
452
454 {
455 if (type == XPathNodeType.SignificantWhitespace || type == XPathNodeType.Whitespace)
456 {
457 return XPathNodeType.Text;
458 }
459 return type;
460 }
461
462 private static string Format(ArrayList numberlist, List<FormatInfo> tokens, string lang, string letter, string groupingSep, string groupingSize)
463 {
465 int num = 0;
466 if (tokens != null)
467 {
468 num = tokens.Count;
469 }
471 if (groupingSize != null)
472 {
473 try
474 {
476 }
477 catch (FormatException)
478 {
479 }
480 catch (OverflowException)
481 {
482 }
483 }
484 if (groupingSep != null)
485 {
486 _ = groupingSep.Length;
487 _ = 1;
488 numberingFormat.setGroupingSeparator(groupingSep);
489 }
490 if (0 < num)
491 {
493 FormatInfo formatInfo2 = null;
494 if (num % 2 == 1)
495 {
496 formatInfo2 = tokens[num - 1];
497 num--;
498 }
499 FormatInfo formatInfo3 = ((2 < num) ? tokens[num - 2] : s_defaultSeparator);
500 FormatInfo formatInfo4 = ((0 < num) ? tokens[num - 1] : s_defaultFormat);
501 if (formatInfo != null)
502 {
503 stringBuilder.Append(formatInfo.formatString);
504 }
505 int count = numberlist.Count;
506 for (int i = 0; i < count; i++)
507 {
508 int num2 = i * 2;
509 bool flag = num2 < num;
510 if (0 < i)
511 {
513 stringBuilder.Append(formatInfo5.formatString);
514 }
515 FormatInfo formatInfo6 = (flag ? tokens[num2 + 1] : formatInfo4);
516 numberingFormat.setNumberingType(formatInfo6.numSequence);
517 numberingFormat.setMinLen(formatInfo6.length);
518 stringBuilder.Append(numberingFormat.FormatItem(numberlist[i]));
519 }
520 if (formatInfo2 != null)
521 {
522 stringBuilder.Append(formatInfo2.formatString);
523 }
524 }
525 else
526 {
527 numberingFormat.setNumberingType(NumberingSequence.FirstDecimal);
528 for (int j = 0; j < numberlist.Count; j++)
529 {
530 if (j != 0)
531 {
532 stringBuilder.Append('.');
533 }
534 stringBuilder.Append(numberingFormat.FormatItem(numberlist[j]));
535 }
536 }
537 return stringBuilder.ToString();
538 }
539
540 private static void mapFormatToken(string wsToken, int startLen, int tokLen, out NumberingSequence seq, out int pminlen)
541 {
542 char c = wsToken[startLen];
543 bool flag = false;
544 pminlen = 1;
546 int num = c;
547 if (num <= 2406)
548 {
549 if (num == 48 || num == 2406)
550 {
551 goto IL_0042;
552 }
553 }
554 else if (num == 3664 || num == 51067 || num == 65296)
555 {
556 goto IL_0042;
557 }
558 goto IL_0071;
559 IL_0071:
560 if (!flag)
561 {
562 switch (wsToken[startLen])
563 {
564 case '1':
565 seq = NumberingSequence.FirstDecimal;
566 break;
567 case 'A':
568 seq = NumberingSequence.FirstAlpha;
569 break;
570 case 'I':
571 seq = NumberingSequence.FirstSpecial;
572 break;
573 case 'a':
574 seq = NumberingSequence.LCLetter;
575 break;
576 case 'i':
577 seq = NumberingSequence.LCRoman;
578 break;
579 case 'А':
580 seq = NumberingSequence.UCRus;
581 break;
582 case 'а':
583 seq = NumberingSequence.LCRus;
584 break;
585 case 'א':
586 seq = NumberingSequence.Hebrew;
587 break;
588 case 'أ':
589 seq = NumberingSequence.ArabicScript;
590 break;
591 case 'अ':
592 seq = NumberingSequence.Hindi2;
593 break;
594 case 'क':
595 seq = NumberingSequence.Hindi1;
596 break;
597 case '१':
598 seq = NumberingSequence.Hindi3;
599 break;
600 case 'ก':
601 seq = NumberingSequence.Thai1;
602 break;
603 case '๑':
604 seq = NumberingSequence.Thai2;
605 break;
606 case 'ア':
607 seq = NumberingSequence.DAiueo;
608 break;
609 case 'イ':
610 seq = NumberingSequence.DIroha;
611 break;
612 case 'ㄱ':
613 seq = NumberingSequence.DChosung;
614 break;
615 case '一':
616 seq = NumberingSequence.FEDecimal;
617 break;
618 case '壱':
619 seq = NumberingSequence.DbNum3;
620 break;
621 case '壹':
622 seq = NumberingSequence.ChnCmplx;
623 break;
624 case '子':
625 seq = NumberingSequence.Zodiac2;
626 break;
627 case '가':
628 seq = NumberingSequence.Ganada;
629 break;
630 case '일':
631 seq = NumberingSequence.KorDbNum1;
632 break;
633 case '하':
634 seq = NumberingSequence.KorDbNum3;
635 break;
636 case '1':
637 seq = NumberingSequence.DArabic;
638 break;
639 case 'ア':
640 seq = NumberingSequence.Aiueo;
641 break;
642 case 'イ':
643 seq = NumberingSequence.Iroha;
644 break;
645 case '甲':
646 if (tokLen > 1 && wsToken[startLen + 1] == '子')
647 {
648 seq = NumberingSequence.Zodiac3;
649 tokLen--;
650 startLen++;
651 }
652 else
653 {
654 seq = NumberingSequence.Zodiac1;
655 }
656 break;
657 default:
658 seq = NumberingSequence.FirstDecimal;
659 break;
660 }
661 }
662 if (flag)
663 {
664 seq = NumberingSequence.FirstDecimal;
665 pminlen = 0;
666 }
667 return;
668 IL_0042:
669 do
670 {
671 pminlen++;
672 }
673 while (--tokLen > 0 && c == wsToken[++startLen]);
674 if (wsToken[startLen] != (ushort)(c + 1))
675 {
676 flag = true;
677 }
678 goto IL_0071;
679 }
680
681 [return: NotNullIfNotNull("formatString")]
682 private static List<FormatInfo> ParseFormat(string formatString)
683 {
684 if (formatString == null || formatString.Length == 0)
685 {
686 return null;
687 }
688 int num = 0;
689 bool flag = CharUtil.IsAlphaNumeric(formatString[num]);
691 int num2 = 0;
692 if (flag)
693 {
694 list.Add(null);
695 }
696 while (num <= formatString.Length)
697 {
698 bool flag2 = ((num < formatString.Length) ? CharUtil.IsAlphaNumeric(formatString[num]) : (!flag));
699 if (flag != flag2)
700 {
702 if (flag)
703 {
704 mapFormatToken(formatString, num2, num - num2, out formatInfo.numSequence, out formatInfo.length);
705 }
706 else
707 {
709 formatInfo.formatString = formatString.Substring(num2, num - num2);
710 }
711 num2 = num;
712 num++;
714 flag = flag2;
715 }
716 else
717 {
718 num++;
719 }
720 }
721 return list;
722 }
723
724 private string ParseLetter(string letter)
725 {
726 switch (letter)
727 {
728 case null:
729 case "traditional":
730 case "alphabetic":
731 return letter;
732 default:
734 {
736 }
737 return null;
738 }
739 }
740}
void Add(TKey key, TValue value)
static int ToInt32(object? value)
Definition Convert.cs:1320
static CultureInfo InvariantCulture
static double Floor(double d)
static string Xslt_CharAttribute
Definition SR.cs:1888
static string Xslt_InvalidAttrValue
Definition SR.cs:1884
Definition SR.cs:7
static TypeCode GetTypeCode(Type? type)
Definition Type.cs:919
static bool Equal(string strA, string strB)
Definition Ref.cs:5
static double ToXPathDouble(object o)
static string ToXPathString(object value)
static double XPathRound(double value)
static bool IsAlphaNumeric(char ch)
Definition CharUtil.cs:7
static void ConvertToRoman(StringBuilder sb, double val, bool upperCase)
static void ConvertToAlphabetic(StringBuilder sb, double val, char firstChar, int totalChars)
static XsltException Create(string res, params string[] args)
string Evaluate(Processor processor, ActionFrame frame)
Definition Avt.cs:37
static Avt CompileAvt(Compiler compiler, string avtText)
Definition Avt.cs:52
void CompileAttributes(Compiler compiler)
static string PrecalculateAvt(ref Avt avt)
FormatInfo(bool isSeparator, string formatString)
static string ConvertToArabic(double val, int minLength, int groupSize, string groupSeparator)
static readonly FormatInfo s_defaultFormat
static string Format(ArrayList numberlist, List< FormatInfo > tokens, string lang, string letter, string groupingSep, string groupingSize)
string ParseLetter(string letter)
static List< FormatInfo > ParseFormat(string formatString)
static void mapFormatToken(string wsToken, int startLen, int tokLen, out NumberingSequence seq, out int pminlen)
override void Execute(Processor processor, ActionFrame frame)
bool checkFrom(Processor processor, XPathNavigator nav)
static object SimplifyValue(object value)
int numberCount(XPathNavigator nav, Processor processor, XPathNavigator contextNode)
override void Compile(Compiler compiler)
int numberAny(Processor processor, ActionFrame frame)
XPathNodeType BasicNodeType(XPathNodeType type)
override bool CompileAttribute(Compiler compiler)
static readonly FormatInfo s_defaultSeparator
bool MatchCountKey(Processor processor, XPathNavigator contextNode, XPathNavigator nav)
bool moveToCount(XPathNavigator nav, Processor processor, XPathNavigator contextNode)
TypeCode
Definition TypeCode.cs:4