Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlJsonReader.cs
Go to the documentation of this file.
3using System.IO;
4using System.Text;
5using System.Xml;
6
8
10{
12 {
15 None
16 }
17
18 private static class CharType
19 {
20 public const byte FirstName = 1;
21
22 public const byte Name = 2;
23
24 public const byte None = 0;
25 }
26
27 private const int MaxTextChunk = 2048;
28
29 private bool _buffered;
30
32
34
36
37 private int _maxBytesPerRead;
38
39 private OnXmlDictionaryReaderClose _onReaderClose;
40
42
43 private int _scopeDepth;
44
46
47 private static ReadOnlySpan<byte> CharTypes => new byte[256]
48 {
49 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
50 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
51 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
52 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
53 0, 0, 0, 0, 0, 2, 2, 0, 2, 2,
54 2, 2, 2, 2, 2, 2, 2, 2, 0, 0,
55 0, 0, 0, 0, 0, 3, 3, 3, 3, 3,
56 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
57 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
58 3, 0, 0, 0, 0, 3, 0, 3, 3, 3,
59 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
60 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
61 3, 3, 3, 0, 0, 0, 0, 0, 3, 3,
62 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
63 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
64 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
65 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
66 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
67 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
68 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
69 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
70 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
71 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
72 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
73 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
74 3, 3, 3, 3, 3, 3
75 };
76
77 public override bool CanCanonicalize => false;
78
79 public override string Value
80 {
81 get
82 {
83 if (IsAttributeValue && !IsLocalName("type"))
84 {
85 return UnescapeJsonString(base.Value);
86 }
87 return base.Value;
88 }
89 }
90
91 private bool IsAttributeValue
92 {
93 get
94 {
95 if (base.Node.NodeType != XmlNodeType.Attribute)
96 {
98 }
99 return true;
100 }
101 }
102
104 {
105 get
106 {
107 if (_scopeDepth > 0)
108 {
109 return _scopes[_scopeDepth] == JsonNodeType.Collection;
110 }
111 return false;
112 }
113 }
114
116 {
117 get
118 {
119 if (!base.Node.IsAtomicValue)
120 {
121 return base.Node.NodeType == XmlNodeType.Text;
122 }
123 return false;
124 }
125 }
126
127 public override void Close()
128 {
129 OnXmlDictionaryReaderClose onReaderClose = _onReaderClose;
130 _onReaderClose = null;
131 ResetState();
132 if (onReaderClose != null)
133 {
134 try
135 {
136 onReaderClose(this);
137 }
139 {
141 }
142 }
143 base.Close();
144 }
145
146 public override void EndCanonicalization()
147 {
148 throw new NotSupportedException();
149 }
150
151 public override string GetAttribute(int index)
152 {
153 return UnescapeJsonString(base.GetAttribute(index));
154 }
155
156 public override string GetAttribute(string localName, string namespaceUri)
157 {
158 if (localName != "type")
159 {
160 return UnescapeJsonString(base.GetAttribute(localName, namespaceUri));
161 }
162 return base.GetAttribute(localName, namespaceUri);
163 }
164
165 public override string GetAttribute(string name)
166 {
167 if (name != "type")
168 {
169 return UnescapeJsonString(base.GetAttribute(name));
170 }
171 return base.GetAttribute(name);
172 }
173
174 public override string GetAttribute(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
175 {
176 if (XmlDictionaryString.GetString(localName) != "type")
177 {
178 return UnescapeJsonString(base.GetAttribute(localName, namespaceUri));
179 }
180 return base.GetAttribute(localName, namespaceUri);
181 }
182
183 public override bool Read()
184 {
185 if (base.Node.CanMoveToElement)
186 {
188 }
189 if (base.Node.ReadState == ReadState.Closed)
190 {
191 return false;
192 }
193 if (base.Node.ExitScope)
194 {
195 ExitScope();
196 }
197 if (!_buffered)
198 {
199 base.BufferReader.SetWindow(base.ElementNode.BufferOffset, _maxBytesPerRead);
200 }
201 byte ch;
203 {
206 {
207 base.BufferReader.SkipByte();
210 }
212 if (TryGetByte(out ch) && ch == 93 && IsReadingCollection)
213 {
214 base.BufferReader.SkipByte();
217 }
218 if (base.BufferReader.EndOfFile)
219 {
220 if (_scopeDepth > 0)
221 {
223 return true;
224 }
226 return false;
227 }
228 }
229 ch = base.BufferReader.GetByte();
230 if (_scopeDepth == 0)
231 {
233 }
234 else if (IsReadingComplexText)
235 {
236 switch (_complexTextMode)
237 {
238 case JsonComplexTextMode.NumericalText:
240 break;
241 case JsonComplexTextMode.QuotedText:
242 if (ch == 92)
243 {
245 }
246 else
247 {
249 }
250 break;
251 case JsonComplexTextMode.None:
253 break;
254 }
255 }
256 else if (IsReadingCollection)
257 {
259 }
260 else if (ch == 93)
261 {
262 base.BufferReader.SkipByte();
265 }
266 else if (ch == 123)
267 {
268 base.BufferReader.SkipByte();
270 ch = base.BufferReader.GetByte();
271 if (ch == 125)
272 {
273 base.BufferReader.SkipByte();
275 if (TryGetByte(out ch))
276 {
277 if (ch == 44)
278 {
279 base.BufferReader.SkipByte();
280 }
281 }
282 else
283 {
285 }
287 }
288 else
289 {
292 }
293 }
294 else if (ch == 125)
295 {
296 base.BufferReader.SkipByte();
298 {
300 ch = base.BufferReader.GetByte();
301 if (ch == 44 || ch == 125)
302 {
303 base.BufferReader.SkipByte();
304 }
305 else
306 {
308 }
310 }
312 }
313 else if (ch == 44)
314 {
315 base.BufferReader.SkipByte();
317 }
318 else if (ch == 34)
319 {
321 {
325 }
326 else if (base.Node.NodeType == XmlNodeType.Element)
327 {
329 {
332 }
333 else
334 {
335 base.BufferReader.SkipByte();
337 }
338 }
339 else if (base.Node.NodeType == XmlNodeType.EndElement)
340 {
343 }
344 else
345 {
347 }
348 }
349 else if (ch == 102)
350 {
351 int offset;
352 byte[] buffer = base.BufferReader.GetBuffer(5, out offset);
353 if (buffer[offset + 1] != 97 || buffer[offset + 2] != 108 || buffer[offset + 3] != 115 || buffer[offset + 4] != 101)
354 {
355 XmlExceptionHelper.ThrowTokenExpected(this, "false", Encoding.UTF8.GetString(buffer, offset, 5));
356 }
357 base.BufferReader.Advance(5);
358 if (TryGetByte(out ch) && !IsWhitespace(ch) && ch != 44 && ch != 125 && ch != 93)
359 {
360 string @string = Encoding.UTF8.GetString(buffer, offset, 4);
361 char c = (char)ch;
362 XmlExceptionHelper.ThrowTokenExpected(this, "false", @string + c);
363 }
365 }
366 else if (ch == 116)
367 {
368 int offset2;
369 byte[] buffer2 = base.BufferReader.GetBuffer(4, out offset2);
370 if (buffer2[offset2 + 1] != 114 || buffer2[offset2 + 2] != 117 || buffer2[offset2 + 3] != 101)
371 {
373 }
374 base.BufferReader.Advance(4);
375 if (TryGetByte(out ch) && !IsWhitespace(ch) && ch != 44 && ch != 125 && ch != 93)
376 {
377 string string2 = Encoding.UTF8.GetString(buffer2, offset2, 4);
378 char c = (char)ch;
380 }
382 }
383 else if (ch == 110)
384 {
385 int offset3;
386 byte[] buffer3 = base.BufferReader.GetBuffer(4, out offset3);
387 if (buffer3[offset3 + 1] != 117 || buffer3[offset3 + 2] != 108 || buffer3[offset3 + 3] != 108)
388 {
390 }
391 base.BufferReader.Advance(4);
393 if (TryGetByte(out ch))
394 {
395 switch (ch)
396 {
397 case 44:
398 case 125:
399 base.BufferReader.SkipByte();
400 break;
401 default:
402 {
403 string string3 = Encoding.UTF8.GetString(buffer3, offset3, 4);
404 char c = (char)ch;
406 break;
407 }
408 case 93:
409 break;
410 }
411 }
412 else
413 {
416 }
418 }
419 else if (ch == 45 || (48 <= ch && ch <= 57) || ch == 73 || ch == 78)
420 {
422 }
423 else
424 {
426 }
427 return true;
428 }
429
430 public override decimal ReadContentAsDecimal()
431 {
432 string text = ReadContentAsString();
433 try
434 {
435 return decimal.Parse(text, NumberStyles.Float, NumberFormatInfo.InvariantInfo);
436 }
438 {
440 }
442 {
444 }
446 {
448 }
449 }
450
451 public override int ReadContentAsInt()
452 {
454 }
455
456 public override long ReadContentAsLong()
457 {
458 string text = ReadContentAsString();
459 try
460 {
461 return long.Parse(text, NumberStyles.Float, NumberFormatInfo.InvariantInfo);
462 }
464 {
466 }
468 {
470 }
472 {
474 }
475 }
476
477 public override int ReadValueAsBase64(byte[] buffer, int offset, int count)
478 {
480 {
481 if (buffer == null)
482 {
483 throw new ArgumentNullException("buffer");
484 }
485 if (offset < 0)
486 {
488 }
489 if (offset > buffer.Length)
490 {
492 }
493 if (count < 0)
494 {
496 }
497 if (count > buffer.Length - offset)
498 {
500 }
501 return 0;
502 }
503 return base.ReadValueAsBase64(buffer, offset, count);
504 }
505
506 public override int ReadValueChunk(char[] chars, int offset, int count)
507 {
509 {
510 if (chars == null)
511 {
512 throw new ArgumentNullException("chars");
513 }
514 if (offset < 0)
515 {
517 }
518 if (offset > chars.Length)
519 {
521 }
522 if (count < 0)
523 {
525 }
526 if (count > chars.Length - offset)
527 {
529 }
530 string text = UnescapeJsonString(base.Node.ValueAsString);
531 int num = Math.Min(count, text.Length);
532 if (num > 0)
533 {
534 text.CopyTo(0, chars, offset, num);
535 if (base.Node.QNameType == QNameType.Xmlns)
536 {
537 base.Node.Namespace.Uri.SetValue(0, 0);
538 }
539 else
540 {
541 base.Node.Value.SetValue(ValueHandleType.UTF8, 0, 0);
542 }
543 }
544 return num;
545 }
546 return base.ReadValueChunk(chars, offset, count);
547 }
548
549 public void SetInput(byte[] buffer, int offset, int count, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose)
550 {
551 if (buffer == null)
552 {
553 throw new ArgumentNullException("buffer");
554 }
555 if (offset < 0)
556 {
558 }
559 if (offset > buffer.Length)
560 {
562 }
563 if (count < 0)
564 {
566 }
567 if (count > buffer.Length - offset)
568 {
570 }
573 base.BufferReader.SetBuffer(arraySegment.Array, arraySegment.Offset, arraySegment.Count, null, null);
574 _buffered = true;
575 ResetState();
576 }
577
578 public void SetInput(Stream stream, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose)
579 {
580 if (stream == null)
581 {
582 throw new ArgumentNullException("stream");
583 }
585 stream = new JsonEncodingStreamWrapper(stream, encoding, isReader: true);
586 base.BufferReader.SetBuffer(stream, null, null);
587 _buffered = false;
588 ResetState();
589 }
590
592 {
593 throw new NotSupportedException();
594 }
595
596 internal static void CheckArray(Array array, int offset, int count)
597 {
598 if (array == null)
599 {
600 throw new ArgumentNullException("array");
601 }
602 if (offset < 0)
603 {
605 }
606 if (offset > array.Length)
607 {
609 }
610 if (count < 0)
611 {
613 }
614 if (count > array.Length - offset)
615 {
617 }
618 }
619
620 private static int BreakText(byte[] buffer, int offset, int length)
621 {
622 if (length > 0 && (buffer[offset + length - 1] & 0x80) == 128)
623 {
624 int num = length;
625 do
626 {
627 length--;
628 }
629 while (length > 0 && (buffer[offset + length] & 0xC0) != 192);
630 if (length == 0)
631 {
632 return num;
633 }
634 byte b = (byte)(buffer[offset + length] << 2);
635 int num2 = 2;
636 while ((b & 0x80) == 128)
637 {
638 b <<= 1;
639 num2++;
640 if (num2 > 4)
641 {
642 return num;
643 }
644 }
645 if (length + num2 == num)
646 {
647 return num;
648 }
649 }
650 return length;
651 }
652
653 private static int ComputeNumericalTextLength(byte[] buffer, int offset, int offsetMax)
654 {
655 int num = offset;
656 while (offset < offsetMax)
657 {
658 byte b = buffer[offset];
659 if (b == 44 || b == 125 || b == 93 || IsWhitespace(b))
660 {
661 break;
662 }
663 offset++;
664 }
665 return offset - num;
666 }
667
668 private static int ComputeQuotedTextLengthUntilEndQuote(byte[] buffer, int offset, int offsetMax, out bool escaped)
669 {
670 int num = offset;
671 escaped = false;
672 for (; offset < offsetMax; offset++)
673 {
674 byte b = buffer[offset];
675 if (b < 32)
676 {
678 }
679 switch (b)
680 {
681 case 92:
682 case 239:
683 escaped = true;
684 break;
685 default:
686 continue;
687 case 34:
688 break;
689 }
690 break;
691 }
692 return offset - num;
693 }
694
695 private static bool IsWhitespace(byte ch)
696 {
697 if (ch != 32 && ch != 9 && ch != 10)
698 {
699 return ch == 13;
700 }
701 return true;
702 }
703
704 private static char ParseChar(string value, NumberStyles style)
705 {
706 int value2 = ParseInt(value, style);
707 try
708 {
709 return Convert.ToChar(value2);
710 }
712 {
714 }
715 }
716
717 private static int ParseInt(string value, NumberStyles style)
718 {
719 try
720 {
721 return int.Parse(value, style, NumberFormatInfo.InvariantInfo);
722 }
724 {
726 }
728 {
730 }
732 {
734 }
735 }
736
737 private void BufferElement()
738 {
739 int offset = base.BufferReader.Offset;
740 bool flag = false;
741 byte b = 0;
742 while (!flag)
743 {
744 int offset2;
745 int offsetMax;
746 byte[] buffer = base.BufferReader.GetBuffer(128, out offset2, out offsetMax);
747 if (offset2 + 128 != offsetMax)
748 {
749 break;
750 }
751 for (int i = offset2; i < offsetMax; i++)
752 {
753 if (flag)
754 {
755 break;
756 }
757 byte b2 = buffer[i];
758 if (b2 == 92)
759 {
760 i++;
761 if (i >= offsetMax)
762 {
763 break;
764 }
765 }
766 else if (b == 0)
767 {
768 if (b2 == 39 || b2 == 34)
769 {
770 b = b2;
771 }
772 if (b2 == 58)
773 {
774 flag = true;
775 }
776 }
777 else if (b2 == b)
778 {
779 b = 0;
780 }
781 }
782 base.BufferReader.Advance(128);
783 }
785 }
786
788 {
789 _scopeDepth++;
790 if (_scopes == null)
791 {
792 _scopes = new JsonNodeType[4];
793 }
794 else if (_scopes.Length == _scopeDepth)
795 {
798 _scopes = array;
799 }
801 }
802
804 {
807 _scopeDepth--;
808 return result;
809 }
810
811 private new void MoveToEndElement()
812 {
814 base.MoveToEndElement();
815 }
816
817 private void MoveToInitial(XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose)
818 {
820 _maxBytesPerRead = quotas.MaxBytesPerRead;
822 }
823
824 private void ParseAndSetLocalName()
825 {
827 xmlElementNode.NameOffset = base.BufferReader.Offset;
828 do
829 {
830 if (base.BufferReader.GetByte() == 92)
831 {
833 }
834 else
835 {
837 }
838 }
839 while (_complexTextMode == JsonComplexTextMode.QuotedText);
840 int num = base.BufferReader.Offset - 1;
841 xmlElementNode.LocalName.SetValue(xmlElementNode.NameOffset, num - xmlElementNode.NameOffset);
842 xmlElementNode.NameLength = num - xmlElementNode.NameOffset;
843 xmlElementNode.Namespace.Uri.SetValue(xmlElementNode.NameOffset, 0);
844 xmlElementNode.Prefix.SetValue(PrefixHandleType.Empty);
848 int @byte = base.BufferReader.GetByte(xmlElementNode.NameOffset);
849 if ((CharTypes[@byte] & 1) == 0)
850 {
852 return;
853 }
854 int num2 = 0;
855 int num3 = xmlElementNode.NameOffset;
856 while (num2 < xmlElementNode.NameLength)
857 {
858 @byte = base.BufferReader.GetByte(num3);
859 if ((CharTypes[@byte] & 2) == 0 || @byte >= 128)
860 {
862 break;
863 }
864 num2++;
865 num3++;
866 }
867 }
868
869 private void ParseStartElement()
870 {
871 if (!_buffered)
872 {
874 }
876 byte @byte = base.BufferReader.GetByte();
877 if (@byte == 34)
878 {
879 base.BufferReader.SkipByte();
884 if (base.BufferReader.GetByte() == 123)
885 {
886 base.BufferReader.SkipByte();
888 }
890 }
891 else
892 {
893 XmlExceptionHelper.ThrowTokenExpected(this, "\"", (char)@byte);
894 }
895 }
896
897 private void ReadAttributes()
898 {
900 xmlAttributeNode.LocalName.SetConstantValue(StringHandleConstStringType.Type);
901 xmlAttributeNode.Namespace.Uri.SetValue(0, 0);
902 xmlAttributeNode.Prefix.SetValue(PrefixHandleType.Empty);
904 byte @byte = base.BufferReader.GetByte();
905 switch (@byte)
906 {
907 case 34:
909 {
910 xmlAttributeNode.Value.SetConstantValue(ValueHandleConstStringType.String);
911 return;
912 }
913 xmlAttributeNode.Value.SetConstantValue(ValueHandleConstStringType.Object);
915 return;
916 case 110:
917 xmlAttributeNode.Value.SetConstantValue(ValueHandleConstStringType.Null);
918 return;
919 case 102:
920 case 116:
921 xmlAttributeNode.Value.SetConstantValue(ValueHandleConstStringType.Boolean);
922 return;
923 case 123:
924 xmlAttributeNode.Value.SetConstantValue(ValueHandleConstStringType.Object);
926 return;
927 case 125:
929 {
930 xmlAttributeNode.Value.SetConstantValue(ValueHandleConstStringType.Object);
931 }
932 else
933 {
935 }
936 return;
937 case 91:
938 xmlAttributeNode.Value.SetConstantValue(ValueHandleConstStringType.Array);
939 base.BufferReader.SkipByte();
940 EnterJsonScope(JsonNodeType.Collection);
941 return;
942 }
943 switch (@byte)
944 {
945 default:
946 if (@byte != 78 && @byte != 73)
947 {
949 break;
950 }
951 goto case 45;
952 case 45:
953 case 48:
954 case 49:
955 case 50:
956 case 51:
957 case 52:
958 case 53:
959 case 54:
960 case 55:
961 case 56:
962 case 57:
963 xmlAttributeNode.Value.SetConstantValue(ValueHandleConstStringType.Number);
964 break;
965 }
966 }
967
969 {
970 base.BufferReader.SkipByte();
971 char c = (char)base.BufferReader.GetByte();
972 switch (c)
973 {
974 case 'u':
975 {
976 base.BufferReader.SkipByte();
977 int offset;
978 byte[] buffer = base.BufferReader.GetBuffer(5, out offset);
979 string @string = Encoding.UTF8.GetString(buffer, offset, 4);
980 base.BufferReader.Advance(4);
981 int num = ParseChar(@string, NumberStyles.HexNumber);
982 if (char.IsHighSurrogate((char)num))
983 {
984 byte @byte = base.BufferReader.GetByte();
985 if (@byte == 92)
986 {
987 base.BufferReader.SkipByte();
989 buffer = base.BufferReader.GetBuffer(5, out offset);
990 @string = Encoding.UTF8.GetString(buffer, offset, 4);
991 base.BufferReader.Advance(4);
992 char c2 = ParseChar(@string, NumberStyles.HexNumber);
993 if (!char.IsLowSurrogate(c2))
994 {
996 }
997 num = new SurrogateChar(c2, (char)num).Char;
998 }
999 }
1000 if (buffer[offset + 4] == 34)
1001 {
1002 base.BufferReader.SkipByte();
1003 if (moveToText)
1004 {
1006 }
1008 }
1009 else
1010 {
1011 if (moveToText)
1012 {
1014 }
1016 }
1017 return;
1018 }
1019 case 'b':
1020 c = '\b';
1021 break;
1022 case 'f':
1023 c = '\f';
1024 break;
1025 case 'n':
1026 c = '\n';
1027 break;
1028 case 'r':
1029 c = '\r';
1030 break;
1031 case 't':
1032 c = '\t';
1033 break;
1034 default:
1036 break;
1037 case '"':
1038 case '/':
1039 case '\\':
1040 break;
1041 }
1042 base.BufferReader.SkipByte();
1043 if (base.BufferReader.GetByte() == 34)
1044 {
1045 base.BufferReader.SkipByte();
1046 if (moveToText)
1047 {
1049 }
1051 }
1052 else
1053 {
1054 if (moveToText)
1055 {
1057 }
1059 }
1060 }
1061
1063 {
1066 xmlElementNode.LocalName.SetConstantValue(elementName);
1067 xmlElementNode.Namespace.Uri.SetValue(xmlElementNode.NameOffset, 0);
1068 xmlElementNode.Prefix.SetValue(PrefixHandleType.Empty);
1069 xmlElementNode.BufferOffset = base.BufferReader.Offset;
1073 }
1074
1075 private int ReadNonFFFE()
1076 {
1077 int offset;
1078 byte[] buffer = base.BufferReader.GetBuffer(3, out offset);
1079 if (buffer[offset + 1] == 191 && (buffer[offset + 2] == 190 || buffer[offset + 2] == 191))
1080 {
1082 }
1083 return 3;
1084 }
1085
1086 private void ReadNumericalText()
1087 {
1088 int offset;
1089 int offsetMax;
1090 int num;
1091 if (_buffered)
1092 {
1093 byte[] buffer = base.BufferReader.GetBuffer(out offset, out offsetMax);
1095 }
1096 else
1097 {
1098 byte[] buffer = base.BufferReader.GetBuffer(2048, out offset, out offsetMax);
1100 num = BreakText(buffer, offset, num);
1101 }
1102 base.BufferReader.Advance(num);
1103 if (offset <= offsetMax - num)
1104 {
1107 }
1108 else
1109 {
1111 _complexTextMode = JsonComplexTextMode.NumericalText;
1112 }
1113 }
1114
1115 private void ReadQuotedText(bool moveToText)
1116 {
1117 int offset;
1118 int offsetMax;
1119 bool escaped;
1120 bool flag;
1121 int num;
1122 if (_buffered)
1123 {
1124 byte[] buffer = base.BufferReader.GetBuffer(out offset, out offsetMax);
1126 flag = offset < offsetMax - num;
1127 }
1128 else
1129 {
1130 byte[] buffer = base.BufferReader.GetBuffer(2048, out offset, out offsetMax);
1132 flag = offset < offsetMax - num;
1133 num = BreakText(buffer, offset, num);
1134 }
1135 if (escaped && base.BufferReader.GetByte() == 239)
1136 {
1137 offset = base.BufferReader.Offset;
1138 num = ReadNonFFFE();
1139 }
1140 base.BufferReader.Advance(num);
1141 if (!escaped && flag)
1142 {
1143 if (moveToText)
1144 {
1146 }
1149 }
1150 else if (num == 0 && escaped)
1151 {
1153 }
1154 else
1155 {
1156 if (moveToText)
1157 {
1159 }
1161 }
1162 }
1163
1165 {
1166 if (!consumedObjectChar)
1167 {
1170 byte @byte = base.BufferReader.GetByte();
1171 if (@byte != 34 && @byte != 125)
1172 {
1173 XmlExceptionHelper.ThrowTokenExpected(this, "\"", (char)@byte);
1174 }
1175 }
1176 else
1177 {
1179 }
1180 byte[] buffer = base.BufferReader.GetBuffer(8, out var offset, out var offsetMax);
1181 if (offset + 8 <= offsetMax && buffer[offset] == 34 && buffer[offset + 1] == 95 && buffer[offset + 2] == 95 && buffer[offset + 3] == 116 && buffer[offset + 4] == 121 && buffer[offset + 5] == 112 && buffer[offset + 6] == 101 && buffer[offset + 7] == 34)
1182 {
1184 xmlAttributeNode.LocalName.SetValue(offset + 1, 6);
1185 xmlAttributeNode.Namespace.Uri.SetValue(0, 0);
1186 xmlAttributeNode.Prefix.SetValue(PrefixHandleType.Empty);
1187 base.BufferReader.Advance(8);
1188 if (!_buffered)
1189 {
1190 BufferElement();
1191 }
1196 buffer = base.BufferReader.GetBuffer(out offset, out offsetMax);
1197 do
1198 {
1199 if (base.BufferReader.GetByte() == 92)
1200 {
1202 }
1203 else
1204 {
1205 ReadQuotedText(moveToText: false);
1206 }
1207 }
1208 while (_complexTextMode == JsonComplexTextMode.QuotedText);
1209 xmlAttributeNode.Value.SetValue(ValueHandleType.UTF8, offset, base.BufferReader.Offset - 1 - offset);
1211 if (base.BufferReader.GetByte() == 44)
1212 {
1213 base.BufferReader.SkipByte();
1215 }
1216 }
1217 if (base.BufferReader.GetByte() == 125)
1218 {
1219 base.BufferReader.SkipByte();
1220 _readServerTypeElement = false;
1222 }
1223 else
1224 {
1226 }
1227 }
1228
1229 private void ResetState()
1230 {
1233 _charactersToSkipOnNextRead = new byte[2];
1234 _scopeDepth = 0;
1235 if (_scopes != null && _scopes.Length > 25)
1236 {
1237 _scopes = null;
1238 }
1239 }
1240
1242 {
1243 Namespace @namespace = AddNamespace();
1244 @namespace.Prefix.SetValue(PrefixHandleType.A);
1245 @namespace.Uri.SetConstantValue(StringHandleConstStringType.Item);
1246 AddXmlnsAttribute(@namespace);
1248 xmlAttributeNode.LocalName.SetConstantValue(StringHandleConstStringType.Item);
1249 xmlAttributeNode.Namespace.Uri.SetValue(0, 0);
1250 xmlAttributeNode.Prefix.SetValue(PrefixHandleType.Empty);
1251 xmlAttributeNode.Value.SetValue(ValueHandleType.UTF8, elementNode.NameOffset, elementNode.NameLength);
1253 elementNode.Prefix.SetValue(PrefixHandleType.A);
1254 elementNode.LocalName.SetConstantValue(StringHandleConstStringType.Item);
1255 elementNode.Namespace = @namespace;
1256 }
1257
1259 {
1260 if (base.BufferReader.GetByte() != characterToSkip)
1261 {
1262 char c = (char)characterToSkip;
1263 XmlExceptionHelper.ThrowTokenExpected(this, c.ToString(), (char)base.BufferReader.GetByte());
1264 }
1265 base.BufferReader.SkipByte();
1266 }
1267
1269 {
1270 byte ch;
1271 while (TryGetByte(out ch) && IsWhitespace(ch))
1272 {
1273 base.BufferReader.SkipByte();
1274 }
1275 }
1276
1277 private bool TryGetByte(out byte ch)
1278 {
1279 int offset;
1280 int offsetMax;
1281 byte[] buffer = base.BufferReader.GetBuffer(1, out offset, out offsetMax);
1282 if (offset < offsetMax)
1283 {
1284 ch = buffer[offset];
1285 return true;
1286 }
1287 ch = 0;
1288 return false;
1289 }
1290
1291 [return: NotNullIfNotNull("val")]
1292 private string UnescapeJsonString(string val)
1293 {
1294 if (val == null)
1295 {
1296 return null;
1297 }
1299 int startIndex = 0;
1300 int num = 0;
1301 for (int i = 0; i < val.Length; i++)
1302 {
1303 if (val[i] == '\\')
1304 {
1305 i++;
1306 if (stringBuilder == null)
1307 {
1309 }
1310 stringBuilder.Append(val, startIndex, num);
1311 if (i >= val.Length)
1312 {
1314 }
1315 switch (val[i])
1316 {
1317 case '"':
1318 case '\'':
1319 case '/':
1320 case '\\':
1321 stringBuilder.Append(val[i]);
1322 break;
1323 case 'b':
1324 stringBuilder.Append('\b');
1325 break;
1326 case 'f':
1327 stringBuilder.Append('\f');
1328 break;
1329 case 'n':
1330 stringBuilder.Append('\n');
1331 break;
1332 case 'r':
1333 stringBuilder.Append('\r');
1334 break;
1335 case 't':
1336 stringBuilder.Append('\t');
1337 break;
1338 case 'u':
1339 if (i + 3 >= val.Length)
1340 {
1342 }
1343 stringBuilder.Append(ParseChar(val.Substring(i + 1, 4), NumberStyles.HexNumber));
1344 i += 4;
1345 break;
1346 }
1347 startIndex = i + 1;
1348 num = 0;
1349 }
1350 else
1351 {
1352 num++;
1353 }
1354 }
1355 if (stringBuilder == null)
1356 {
1357 return val;
1358 }
1359 if (num > 0)
1360 {
1361 stringBuilder.Append(val, startIndex, num);
1362 }
1363 return stringBuilder.ToString();
1364 }
1365
1370}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
static char ToChar(object? value)
Definition Convert.cs:618
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static ArraySegment< byte > ProcessBuffer(byte[] buffer, int offset, int count, Encoding encoding)
void EnterJsonScope(JsonNodeType currentNodeType)
override int ReadValueAsBase64(byte[] buffer, int offset, int count)
override void StartCanonicalization(Stream stream, bool includeComments, string[] inclusivePrefixes)
override string GetAttribute(string localName, string namespaceUri)
static int ComputeQuotedTextLengthUntilEndQuote(byte[] buffer, int offset, int offsetMax, out bool escaped)
void ReadServerTypeAttribute(bool consumedObjectChar)
override string GetAttribute(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
void SetJsonNameWithMapping(XmlElementNode elementNode)
void ReadNonExistentElementName(StringHandleConstStringType elementName)
static void CheckArray(Array array, int offset, int count)
static int ParseInt(string value, NumberStyles style)
static char ParseChar(string value, NumberStyles style)
void SetInput(Stream stream, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose)
void SetInput(byte[] buffer, int offset, int count, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose)
static int BreakText(byte[] buffer, int offset, int length)
override XmlSigningNodeWriter CreateSigningNodeWriter()
static int ComputeNumericalTextLength(byte[] buffer, int offset, int offsetMax)
void SkipExpectedByteInBufferReader(byte characterToSkip)
override int ReadValueChunk(char[] chars, int offset, int count)
void MoveToInitial(XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose)
static string InvalidCharacterEncountered
Definition SR.cs:546
static string JsonInvalidFFFE
Definition SR.cs:548
static string GenericCallbackException
Definition SR.cs:538
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string JsonSizeExceedsRemainingBufferSpace
Definition SR.cs:544
static string ValueMustBeNonNegative
Definition SR.cs:296
static string JsonOffsetExceedsBufferSize
Definition SR.cs:542
static string SizeExceedsRemainingBufferSpace
Definition SR.cs:324
static string XmlInvalidLowSurrogate
Definition SR.cs:342
static string JsonEncounteredUnexpectedCharacter
Definition SR.cs:540
static string JsonMethodNotSupported
Definition SR.cs:554
static string OffsetExceedsBufferSize
Definition SR.cs:322
Definition SR.cs:7
static Encoding UTF8
Definition Encoding.cs:526
void SetValue(PrefixHandleType type)
void SetValue(ValueHandleType type)
void SetCharValue(int ch)
override bool IsLocalName(string localName)
override bool MoveToElement()
XmlComplexTextNode MoveToComplexText()
override string ReadContentAsString()
XmlAtomicTextNode MoveToAtomicText()
XmlAttributeNode AddXmlnsAttribute(Namespace ns)
XmlAttributeNode AddAttribute()
XmlElementNode EnterScope()
static string GetString(XmlDictionaryString s)
static void ThrowTokenExpected(XmlDictionaryReader reader, string expected, char found)
static void ThrowXmlException(XmlDictionaryReader reader, string res)
static XmlException CreateConversionException(string type, Exception exception)