Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlCharCheckingReader.cs
Go to the documentation of this file.
2
3namespace System.Xml;
4
6{
7 private enum State
8 {
11 Error,
13 }
14
15 private State _state;
16
17 private readonly bool _checkCharacters;
18
19 private readonly bool _ignoreWhitespace;
20
21 private readonly bool _ignoreComments;
22
23 private readonly bool _ignorePis;
24
25 private readonly DtdProcessing _dtdProcessing;
26
28
30
32 {
33 get
34 {
36 settings = ((settings != null) ? settings.Clone() : new XmlReaderSettings());
38 {
40 }
42 {
44 }
46 {
48 }
49 if (_ignorePis)
50 {
52 }
53 if (_dtdProcessing != (DtdProcessing)(-1))
54 {
56 }
57 settings.ReadOnly = true;
58 return settings;
59 }
60 }
61
62 public override ReadState ReadState
63 {
64 get
65 {
66 switch (_state)
67 {
68 case State.Initial:
69 if (reader.ReadState != ReadState.Closed)
70 {
71 return ReadState.Initial;
72 }
73 return ReadState.Closed;
74 case State.Error:
75 return ReadState.Error;
76 default:
77 return reader.ReadState;
78 }
79 }
80 }
81
82 public override bool CanReadBinaryContent => true;
83
95
96 public override bool MoveToAttribute(string name)
97 {
98 if (_state == State.InReadBinary)
99 {
101 }
102 return reader.MoveToAttribute(name);
103 }
104
105 public override bool MoveToAttribute(string name, string ns)
106 {
107 if (_state == State.InReadBinary)
108 {
110 }
111 return reader.MoveToAttribute(name, ns);
112 }
113
114 public override void MoveToAttribute(int i)
115 {
116 if (_state == State.InReadBinary)
117 {
119 }
121 }
122
123 public override bool MoveToFirstAttribute()
124 {
125 if (_state == State.InReadBinary)
126 {
128 }
130 }
131
132 public override bool MoveToNextAttribute()
133 {
134 if (_state == State.InReadBinary)
135 {
137 }
139 }
140
141 public override bool MoveToElement()
142 {
143 if (_state == State.InReadBinary)
144 {
146 }
147 return reader.MoveToElement();
148 }
149
150 public override bool Read()
151 {
152 switch (_state)
153 {
154 case State.Initial:
155 _state = State.Interactive;
156 if (reader.ReadState != 0)
157 {
158 break;
159 }
160 goto case State.Interactive;
161 case State.Error:
162 return false;
163 case State.InReadBinary:
165 _state = State.Interactive;
166 goto case State.Interactive;
167 case State.Interactive:
168 if (!reader.Read())
169 {
170 return false;
171 }
172 break;
173 default:
174 return false;
175 }
176 XmlNodeType nodeType = reader.NodeType;
177 if (!_checkCharacters)
178 {
179 switch (nodeType)
180 {
181 case XmlNodeType.Comment:
182 if (_ignoreComments)
183 {
184 return Read();
185 }
186 break;
187 case XmlNodeType.Whitespace:
189 {
190 return Read();
191 }
192 break;
193 case XmlNodeType.ProcessingInstruction:
194 if (_ignorePis)
195 {
196 return Read();
197 }
198 break;
199 case XmlNodeType.DocumentType:
200 if (_dtdProcessing == DtdProcessing.Prohibit)
201 {
202 Throw(System.SR.Xml_DtdIsProhibitedEx, string.Empty);
203 }
204 else if (_dtdProcessing == DtdProcessing.Ignore)
205 {
206 return Read();
207 }
208 break;
209 }
210 return true;
211 }
212 switch (nodeType)
213 {
214 case XmlNodeType.Element:
215 if (!_checkCharacters)
216 {
217 break;
218 }
221 {
222 do
223 {
226 }
227 while (reader.MoveToNextAttribute());
229 }
230 break;
231 case XmlNodeType.Text:
232 case XmlNodeType.CDATA:
234 {
236 }
237 break;
238 case XmlNodeType.EntityReference:
240 {
242 }
243 break;
244 case XmlNodeType.ProcessingInstruction:
245 if (_ignorePis)
246 {
247 return Read();
248 }
250 {
253 }
254 break;
255 case XmlNodeType.Comment:
256 if (_ignoreComments)
257 {
258 return Read();
259 }
261 {
263 }
264 break;
265 case XmlNodeType.DocumentType:
266 if (_dtdProcessing == DtdProcessing.Prohibit)
267 {
268 Throw(System.SR.Xml_DtdIsProhibitedEx, string.Empty);
269 }
270 else if (_dtdProcessing == DtdProcessing.Ignore)
271 {
272 return Read();
273 }
275 {
278 string attribute = reader.GetAttribute("SYSTEM");
279 if (attribute != null)
280 {
282 }
283 attribute = reader.GetAttribute("PUBLIC");
284 int invCharIndex;
285 if (attribute != null && (invCharIndex = XmlCharType.IsPublicId(attribute)) >= 0)
286 {
288 }
289 }
290 break;
291 case XmlNodeType.Whitespace:
293 {
294 return Read();
295 }
297 {
299 }
300 break;
301 case XmlNodeType.SignificantWhitespace:
303 {
305 }
306 break;
307 case XmlNodeType.EndElement:
309 {
311 }
312 break;
313 }
314 _lastNodeType = nodeType;
315 return true;
316 }
317
318 public override bool ReadAttributeValue()
319 {
320 if (_state == State.InReadBinary)
321 {
323 }
324 return reader.ReadAttributeValue();
325 }
326
327 public override int ReadContentAsBase64(byte[] buffer, int index, int count)
328 {
329 if (ReadState != ReadState.Interactive)
330 {
331 return 0;
332 }
333 if (_state != State.InReadBinary)
334 {
335 if (base.CanReadBinaryContent && !_checkCharacters)
336 {
337 _readBinaryHelper = null;
338 _state = State.InReadBinary;
340 }
342 }
343 else if (_readBinaryHelper == null)
344 {
345 return base.ReadContentAsBase64(buffer, index, count);
346 }
347 _state = State.Interactive;
349 _state = State.InReadBinary;
350 return result;
351 }
352
353 public override int ReadContentAsBinHex(byte[] buffer, int index, int count)
354 {
355 if (ReadState != ReadState.Interactive)
356 {
357 return 0;
358 }
359 if (_state != State.InReadBinary)
360 {
361 if (base.CanReadBinaryContent && !_checkCharacters)
362 {
363 _readBinaryHelper = null;
364 _state = State.InReadBinary;
366 }
368 }
369 else if (_readBinaryHelper == null)
370 {
371 return base.ReadContentAsBinHex(buffer, index, count);
372 }
373 _state = State.Interactive;
375 _state = State.InReadBinary;
376 return result;
377 }
378
379 public override int ReadElementContentAsBase64(byte[] buffer, int index, int count)
380 {
381 if (buffer == null)
382 {
383 throw new ArgumentNullException("buffer");
384 }
385 if (count < 0)
386 {
387 throw new ArgumentOutOfRangeException("count");
388 }
389 if (index < 0)
390 {
391 throw new ArgumentOutOfRangeException("index");
392 }
393 if (buffer.Length - index < count)
394 {
395 throw new ArgumentOutOfRangeException("count");
396 }
397 if (ReadState != ReadState.Interactive)
398 {
399 return 0;
400 }
401 if (_state != State.InReadBinary)
402 {
403 if (base.CanReadBinaryContent && !_checkCharacters)
404 {
405 _readBinaryHelper = null;
406 _state = State.InReadBinary;
408 }
410 }
411 else if (_readBinaryHelper == null)
412 {
413 return base.ReadElementContentAsBase64(buffer, index, count);
414 }
415 _state = State.Interactive;
417 _state = State.InReadBinary;
418 return result;
419 }
420
421 public override int ReadElementContentAsBinHex(byte[] buffer, int index, int count)
422 {
423 if (buffer == null)
424 {
425 throw new ArgumentNullException("buffer");
426 }
427 if (count < 0)
428 {
429 throw new ArgumentOutOfRangeException("count");
430 }
431 if (index < 0)
432 {
433 throw new ArgumentOutOfRangeException("index");
434 }
435 if (buffer.Length - index < count)
436 {
437 throw new ArgumentOutOfRangeException("count");
438 }
439 if (ReadState != ReadState.Interactive)
440 {
441 return 0;
442 }
443 if (_state != State.InReadBinary)
444 {
445 if (base.CanReadBinaryContent && !_checkCharacters)
446 {
447 _readBinaryHelper = null;
448 _state = State.InReadBinary;
450 }
452 }
453 else if (_readBinaryHelper == null)
454 {
455 return base.ReadElementContentAsBinHex(buffer, index, count);
456 }
457 _state = State.Interactive;
459 _state = State.InReadBinary;
460 return result;
461 }
462
463 private void Throw(string res, string arg)
464 {
465 _state = State.Error;
466 throw new XmlException(res, arg, (IXmlLineInfo)null);
467 }
468
469 private void Throw(string res, string[] args)
470 {
471 _state = State.Error;
472 throw new XmlException(res, args, null);
473 }
474
483
484 private void ValidateQName(string name)
485 {
487 }
488
489 private void ValidateQName(string prefix, string localName)
490 {
491 try
492 {
493 if (prefix.Length > 0)
494 {
496 }
498 }
499 catch
500 {
501 _state = State.Error;
502 throw;
503 }
504 }
505
506 private void CheckCharacters(string value)
507 {
508 XmlConvert.VerifyCharData(value, ExceptionType.ArgumentException, ExceptionType.XmlException);
509 }
510
511 private void FinishReadBinary()
512 {
513 _state = State.Interactive;
514 if (_readBinaryHelper != null)
515 {
517 }
518 }
519
520 public override async Task<bool> ReadAsync()
521 {
522 switch (_state)
523 {
524 case State.Initial:
525 _state = State.Interactive;
526 if (reader.ReadState != 0)
527 {
528 break;
529 }
530 goto case State.Interactive;
531 case State.Error:
532 return false;
533 case State.InReadBinary:
535 _state = State.Interactive;
536 goto case State.Interactive;
537 case State.Interactive:
539 {
540 return false;
541 }
542 break;
543 default:
544 return false;
545 }
546 XmlNodeType nodeType = reader.NodeType;
547 if (!_checkCharacters)
548 {
549 switch (nodeType)
550 {
551 case XmlNodeType.Comment:
552 if (_ignoreComments)
553 {
555 }
556 break;
557 case XmlNodeType.Whitespace:
559 {
561 }
562 break;
563 case XmlNodeType.ProcessingInstruction:
564 if (_ignorePis)
565 {
567 }
568 break;
569 case XmlNodeType.DocumentType:
570 if (_dtdProcessing == DtdProcessing.Prohibit)
571 {
572 Throw(System.SR.Xml_DtdIsProhibitedEx, string.Empty);
573 }
574 else if (_dtdProcessing == DtdProcessing.Ignore)
575 {
577 }
578 break;
579 }
580 return true;
581 }
582 switch (nodeType)
583 {
584 case XmlNodeType.Element:
585 if (!_checkCharacters)
586 {
587 break;
588 }
591 {
592 do
593 {
596 }
597 while (reader.MoveToNextAttribute());
599 }
600 break;
601 case XmlNodeType.Text:
602 case XmlNodeType.CDATA:
604 {
606 }
607 break;
608 case XmlNodeType.EntityReference:
610 {
612 }
613 break;
614 case XmlNodeType.ProcessingInstruction:
615 if (_ignorePis)
616 {
618 }
620 {
623 }
624 break;
625 case XmlNodeType.Comment:
626 if (_ignoreComments)
627 {
629 }
631 {
633 }
634 break;
635 case XmlNodeType.DocumentType:
636 if (_dtdProcessing == DtdProcessing.Prohibit)
637 {
638 Throw(System.SR.Xml_DtdIsProhibitedEx, string.Empty);
639 }
640 else if (_dtdProcessing == DtdProcessing.Ignore)
641 {
643 }
645 {
648 string attribute = reader.GetAttribute("SYSTEM");
649 if (attribute != null)
650 {
652 }
653 attribute = reader.GetAttribute("PUBLIC");
654 int invCharIndex;
655 if (attribute != null && (invCharIndex = XmlCharType.IsPublicId(attribute)) >= 0)
656 {
658 }
659 }
660 break;
661 case XmlNodeType.Whitespace:
663 {
665 }
667 {
669 }
670 break;
671 case XmlNodeType.SignificantWhitespace:
673 {
675 }
676 break;
677 case XmlNodeType.EndElement:
679 {
681 }
682 break;
683 }
684 _lastNodeType = nodeType;
685 return true;
686 }
687
688 public override async Task<int> ReadContentAsBase64Async(byte[] buffer, int index, int count)
689 {
690 if (ReadState != ReadState.Interactive)
691 {
692 return 0;
693 }
694 if (_state != State.InReadBinary)
695 {
696 if (base.CanReadBinaryContent && !_checkCharacters)
697 {
698 _readBinaryHelper = null;
699 _state = State.InReadBinary;
701 }
703 }
704 else if (_readBinaryHelper == null)
705 {
706 return await base.ReadContentAsBase64Async(buffer, index, count).ConfigureAwait(continueOnCapturedContext: false);
707 }
708 _state = State.Interactive;
710 _state = State.InReadBinary;
711 return result;
712 }
713
714 public override async Task<int> ReadContentAsBinHexAsync(byte[] buffer, int index, int count)
715 {
716 if (ReadState != ReadState.Interactive)
717 {
718 return 0;
719 }
720 if (_state != State.InReadBinary)
721 {
722 if (base.CanReadBinaryContent && !_checkCharacters)
723 {
724 _readBinaryHelper = null;
725 _state = State.InReadBinary;
727 }
729 }
730 else if (_readBinaryHelper == null)
731 {
732 return await base.ReadContentAsBinHexAsync(buffer, index, count).ConfigureAwait(continueOnCapturedContext: false);
733 }
734 _state = State.Interactive;
736 _state = State.InReadBinary;
737 return result;
738 }
739
741 {
742 if (buffer == null)
743 {
744 throw new ArgumentNullException("buffer");
745 }
746 if (count < 0)
747 {
748 throw new ArgumentOutOfRangeException("count");
749 }
750 if (index < 0)
751 {
752 throw new ArgumentOutOfRangeException("index");
753 }
754 if (buffer.Length - index < count)
755 {
756 throw new ArgumentOutOfRangeException("count");
757 }
758 if (ReadState != ReadState.Interactive)
759 {
760 return 0;
761 }
762 if (_state != State.InReadBinary)
763 {
764 if (base.CanReadBinaryContent && !_checkCharacters)
765 {
766 _readBinaryHelper = null;
767 _state = State.InReadBinary;
769 }
771 }
772 else if (_readBinaryHelper == null)
773 {
774 return await base.ReadElementContentAsBase64Async(buffer, index, count).ConfigureAwait(continueOnCapturedContext: false);
775 }
776 _state = State.Interactive;
778 _state = State.InReadBinary;
779 return result;
780 }
781
783 {
784 if (buffer == null)
785 {
786 throw new ArgumentNullException("buffer");
787 }
788 if (count < 0)
789 {
790 throw new ArgumentOutOfRangeException("count");
791 }
792 if (index < 0)
793 {
794 throw new ArgumentOutOfRangeException("index");
795 }
796 if (buffer.Length - index < count)
797 {
798 throw new ArgumentOutOfRangeException("count");
799 }
800 if (ReadState != ReadState.Interactive)
801 {
802 return 0;
803 }
804 if (_state != State.InReadBinary)
805 {
806 if (base.CanReadBinaryContent && !_checkCharacters)
807 {
808 _readBinaryHelper = null;
809 _state = State.InReadBinary;
811 }
813 }
814 else if (_readBinaryHelper == null)
815 {
816 return await base.ReadElementContentAsBinHexAsync(buffer, index, count).ConfigureAwait(continueOnCapturedContext: false);
817 }
818 _state = State.Interactive;
820 _state = State.InReadBinary;
821 return result;
822 }
823
825 {
826 _state = State.Interactive;
827 if (_readBinaryHelper != null)
828 {
830 }
831 }
832}
static string Xml_InvalidCharacter
Definition SR.cs:110
static string Xml_DtdIsProhibitedEx
Definition SR.cs:160
static string Xml_InvalidWhitespaceCharacter
Definition SR.cs:200
Definition SR.cs:7
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)
Definition Task.cs:226
async Task< int > ReadElementContentAsBase64Async(byte[] buffer, int index, int count)
static ReadContentAsBinaryHelper CreateOrReset(ReadContentAsBinaryHelper helper, XmlReader reader)
async Task< int > ReadContentAsBase64Async(byte[] buffer, int index, int count)
int ReadContentAsBase64(byte[] buffer, int index, int count)
int ReadContentAsBinHex(byte[] buffer, int index, int count)
int ReadElementContentAsBinHex(byte[] buffer, int index, int count)
int ReadElementContentAsBase64(byte[] buffer, int index, int count)
async Task< int > ReadElementContentAsBinHexAsync(byte[] buffer, int index, int count)
async Task< int > ReadContentAsBinHexAsync(byte[] buffer, int index, int count)
static string ParseNCNameThrow(string s)
static int ParseQNameThrow(string s)
void ValidateQName(string prefix, string localName)
override bool MoveToAttribute(string name, string ns)
override async Task< bool > ReadAsync()
override int ReadContentAsBinHex(byte[] buffer, int index, int count)
override async Task< int > ReadContentAsBase64Async(byte[] buffer, int index, int count)
override int ReadContentAsBase64(byte[] buffer, int index, int count)
override int ReadElementContentAsBinHex(byte[] buffer, int index, int count)
XmlCharCheckingReader(XmlReader reader, bool checkCharacters, bool ignoreWhitespace, bool ignoreComments, bool ignorePis, DtdProcessing dtdProcessing)
void Throw(string res, string[] args)
override async Task< int > ReadElementContentAsBase64Async(byte[] buffer, int index, int count)
override bool MoveToAttribute(string name)
void Throw(string res, string arg)
override XmlReaderSettings Settings
ReadContentAsBinaryHelper _readBinaryHelper
override int ReadElementContentAsBase64(byte[] buffer, int index, int count)
override async Task< int > ReadElementContentAsBinHexAsync(byte[] buffer, int index, int count)
override async Task< int > ReadContentAsBinHexAsync(byte[] buffer, int index, int count)
static int IsOnlyWhitespaceWithPos(string str)
static int IsPublicId(string str)
static void VerifyCharData(string data, ExceptionType exceptionType)
static string[] BuildCharExceptionArgs(string data, int invCharIndex)
string? GetAttribute(string name)
bool MoveToAttribute(string name)
virtual ? XmlReaderSettings Settings
Definition XmlReader.cs:60
virtual Task< bool > ReadAsync()
XmlNodeType NodeType
Definition XmlReader.cs:62
virtual Task< string > GetValueAsync()
virtual string Name
Definition XmlReader.cs:65