Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XsdCachingReader.cs
Go to the documentation of this file.
3
4namespace System.Xml;
5
6internal sealed class XsdCachingReader : XmlReader, IXmlLineInfo
7{
8 private enum CachingReaderState
9 {
10 None,
11 Init,
12 Record,
13 Replay,
15 Error
16 }
17
19
21
23
25
27
29
30 private int _contentIndex;
31
32 private int _attributeCount;
33
35
37
38 private int _currentAttrIndex;
39
41
42 private bool _readAhead;
43
44 private readonly IXmlLineInfo _lineInfo;
45
47
49
51
53
54 public override string LocalName => _cachedNode.LocalName;
55
56 public override string NamespaceURI => _cachedNode.Namespace;
57
58 public override string Prefix => _cachedNode.Prefix;
59
61
62 public override string Value
63 {
64 get
65 {
67 {
68 return _cachedNode.RawValue;
69 }
71 }
72 }
73
74 public override int Depth => _cachedNode.Depth;
75
76 public override string BaseURI => _coreReader.BaseURI;
77
78 public override bool IsEmptyElement => false;
79
80 public override bool IsDefault => false;
81
82 public override char QuoteChar => _coreReader.QuoteChar;
83
85
86 public override string XmlLang => _coreReader.XmlLang;
87
88 public override int AttributeCount => _attributeCount;
89
90 public override string this[int i] => GetAttribute(i);
91
92 public override string this[string name, string namespaceURI] => GetAttribute(name, namespaceURI);
93
94 public override bool EOF
95 {
96 get
97 {
98 if (_cacheState == CachingReaderState.ReaderClosed)
99 {
100 return _coreReader.EOF;
101 }
102 return false;
103 }
104 }
105
107
109
111
113
123
124 [MemberNotNull("_coreReaderNameTable")]
143
144 internal void Reset(XmlReader reader)
145 {
146 _coreReader = reader;
147 Init();
148 }
149
150 public override string GetAttribute(string name)
151 {
152 int num = (name.Contains(':') ? GetAttributeIndexWithPrefix(name) : GetAttributeIndexWithoutPrefix(name));
153 if (num < 0)
154 {
155 return null;
156 }
157 return _attributeEvents[num].RawValue;
158 }
159
160 public override string GetAttribute(string name, string namespaceURI)
161 {
163 string strB = _coreReaderNameTable.Get(name);
164 for (int i = 0; i < _attributeCount; i++)
165 {
168 {
170 }
171 }
172 return null;
173 }
174
175 public override string GetAttribute(int i)
176 {
178 {
179 throw new ArgumentOutOfRangeException("i");
180 }
181 return _attributeEvents[i].RawValue;
182 }
183
184 public override bool MoveToAttribute(string name)
185 {
186 int num = (name.Contains(':') ? GetAttributeIndexWithPrefix(name) : GetAttributeIndexWithoutPrefix(name));
187 if (num >= 0)
188 {
189 _currentAttrIndex = num;
191 return true;
192 }
193 return false;
194 }
195
196 public override bool MoveToAttribute(string name, string ns)
197 {
198 ns = ((ns == null) ? string.Empty : _coreReaderNameTable.Get(ns));
199 string strB = _coreReaderNameTable.Get(name);
200 for (int i = 0; i < _attributeCount; i++)
201 {
203 if (Ref.Equal(validatingReaderNodeData.LocalName, strB) && Ref.Equal(validatingReaderNodeData.Namespace, ns))
204 {
207 return true;
208 }
209 }
210 return false;
211 }
212
213 public override void MoveToAttribute(int i)
214 {
216 {
217 throw new ArgumentOutOfRangeException("i");
218 }
221 }
222
223 public override bool MoveToFirstAttribute()
224 {
225 if (_attributeCount == 0)
226 {
227 return false;
228 }
231 return true;
232 }
233
234 public override bool MoveToNextAttribute()
235 {
237 {
239 return true;
240 }
241 return false;
242 }
243
244 public override bool MoveToElement()
245 {
246 if (_cacheState != CachingReaderState.Replay || _cachedNode.NodeType != XmlNodeType.Attribute)
247 {
248 return false;
249 }
252 Read();
253 return true;
254 }
255
256 public override bool Read()
257 {
258 switch (_cacheState)
259 {
260 case CachingReaderState.Init:
262 goto case CachingReaderState.Record;
263 case CachingReaderState.Record:
264 {
266 if (_coreReader.Read())
267 {
268 switch (_coreReader.NodeType)
269 {
270 case XmlNodeType.Element:
271 _cacheState = CachingReaderState.ReaderClosed;
272 return false;
273 case XmlNodeType.EndElement:
277 break;
278 case XmlNodeType.Text:
279 case XmlNodeType.CDATA:
280 case XmlNodeType.ProcessingInstruction:
281 case XmlNodeType.Comment:
282 case XmlNodeType.Whitespace:
283 case XmlNodeType.SignificantWhitespace:
288 break;
289 }
291 return true;
292 }
293 _cacheState = CachingReaderState.ReaderClosed;
294 return false;
295 }
296 case CachingReaderState.Replay:
298 {
299 _cacheState = CachingReaderState.ReaderClosed;
300 _cacheHandler(this);
301 if (_coreReader.NodeType != XmlNodeType.Element || _readAhead)
302 {
303 return _coreReader.Read();
304 }
305 return true;
306 }
308 if (_currentContentIndex > 0)
309 {
311 }
313 return true;
314 default:
315 return false;
316 }
317 }
318
319 internal ValidatingReaderNodeData RecordTextNode(string textValue, string originalStringValue, int depth, int lineNo, int linePos)
320 {
322 validatingReaderNodeData.SetItemData(textValue, originalStringValue);
323 validatingReaderNodeData.SetLineInfo(lineNo, linePos);
326 }
327
336
347
349 {
351 string result = InternalReadContentAsString();
353 return result;
354 }
355
356 public override void Close()
357 {
359 _cacheState = CachingReaderState.ReaderClosed;
360 }
361
362 public override void Skip()
363 {
365 if (nodeType != XmlNodeType.Element)
366 {
367 if (nodeType != XmlNodeType.Attribute)
368 {
369 Read();
370 return;
371 }
373 }
374 if (_coreReader.NodeType != XmlNodeType.EndElement && !_readAhead)
375 {
376 int num = _coreReader.Depth - 1;
377 while (_coreReader.Read() && _coreReader.Depth > num)
378 {
379 }
380 }
382 _cacheState = CachingReaderState.ReaderClosed;
383 _cacheHandler(this);
384 }
385
386 public override string LookupNamespace(string prefix)
387 {
389 }
390
391 public override void ResolveEntity()
392 {
393 throw new InvalidOperationException();
394 }
395
396 public override bool ReadAttributeValue()
397 {
398 if (_cachedNode.NodeType != XmlNodeType.Attribute)
399 {
400 return false;
401 }
403 return true;
404 }
405
407 {
408 return true;
409 }
410
411 internal void SetToReplayMode()
412 {
416 Read();
417 }
418
420 {
421 return _coreReader;
422 }
423
425 {
426 return _lineInfo;
427 }
428
429 private void ClearAttributesInfo()
430 {
431 _attributeCount = 0;
433 }
434
457
482
501
502 private int GetAttributeIndexWithoutPrefix(string name)
503 {
504 string text = _coreReaderNameTable.Get(name);
505 if (text == null)
506 {
507 return -1;
508 }
509 for (int i = 0; i < _attributeCount; i++)
510 {
512 if (Ref.Equal(validatingReaderNodeData.LocalName, text) && validatingReaderNodeData.Prefix.Length == 0)
513 {
514 return i;
515 }
516 }
517 return -1;
518 }
519
520 private int GetAttributeIndexWithPrefix(string name)
521 {
522 string text = _coreReaderNameTable.Get(name);
523 if (text == null)
524 {
525 return -1;
526 }
527 for (int i = 0; i < _attributeCount; i++)
528 {
530 if (Ref.Equal(validatingReaderNodeData.GetAtomizedNameWPrefix(_coreReaderNameTable), text))
531 {
532 return i;
533 }
534 }
535 return -1;
536 }
537
539 {
540 if (_textNode == null)
541 {
543 }
544 _textNode.Depth = depth;
546 return _textNode;
547 }
548
549 public override Task<string> GetValueAsync()
550 {
552 {
553 return Task.FromResult(_cachedNode.OriginalStringValue);
554 }
555 return Task.FromResult(_cachedNode.RawValue);
556 }
557
558 public override async Task<bool> ReadAsync()
559 {
560 switch (_cacheState)
561 {
562 case CachingReaderState.Init:
564 goto case CachingReaderState.Record;
565 case CachingReaderState.Record:
566 {
569 {
570 switch (_coreReader.NodeType)
571 {
572 case XmlNodeType.Element:
573 _cacheState = CachingReaderState.ReaderClosed;
574 return false;
575 case XmlNodeType.EndElement:
578 recordedNode.SetLineInfo(_lineInfo);
579 break;
580 case XmlNodeType.Text:
581 case XmlNodeType.CDATA:
582 case XmlNodeType.ProcessingInstruction:
583 case XmlNodeType.Comment:
584 case XmlNodeType.Whitespace:
585 case XmlNodeType.SignificantWhitespace:
586 {
590 recordedNode.SetLineInfo(_lineInfo);
592 break;
593 }
594 }
596 return true;
597 }
598 _cacheState = CachingReaderState.ReaderClosed;
599 return false;
600 }
601 case CachingReaderState.Replay:
603 {
604 _cacheState = CachingReaderState.ReaderClosed;
605 _cacheHandler(this);
606 if (_coreReader.NodeType != XmlNodeType.Element || _readAhead)
607 {
609 }
610 return true;
611 }
613 if (_currentContentIndex > 0)
614 {
616 }
618 return true;
619 default:
620 return false;
621 }
622 }
623
624 public override async Task SkipAsync()
625 {
627 if (nodeType != XmlNodeType.Element)
628 {
629 if (nodeType != XmlNodeType.Attribute)
630 {
632 return;
633 }
635 }
636 if (_coreReader.NodeType != XmlNodeType.EndElement && !_readAhead)
637 {
640 {
641 }
642 }
644 _cacheState = CachingReaderState.ReaderClosed;
645 _cacheHandler(this);
646 }
647
649 {
653 return ReadAsync();
654 }
655}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)
Definition Task.cs:226
static bool Equal(string strA, string strB)
Definition Ref.cs:5
void SetItemData(string localName, string prefix, string ns, int depth)
string GetAtomizedNameWPrefix(XmlNameTable nameTable)
string? Get(char[] array, int offset, int length)
virtual XmlSpace XmlSpace
Definition XmlReader.cs:96
virtual ? XmlReaderSettings Settings
Definition XmlReader.cs:60
static bool HasValueInternal(XmlNodeType nodeType)
virtual char QuoteChar
Definition XmlReader.cs:94
virtual Task< bool > ReadAsync()
virtual string XmlLang
Definition XmlReader.cs:98
string? LookupNamespace(string prefix)
virtual void Close()
Definition XmlReader.cs:528
XmlNodeType NodeType
Definition XmlReader.cs:62
XmlNameTable NameTable
Definition XmlReader.cs:116
virtual Task< string > GetValueAsync()
string InternalReadContentAsString()
override Task< string > GetValueAsync()
override async Task< bool > ReadAsync()
ValidatingReaderNodeData AddContent(XmlNodeType nodeType)
override bool MoveToAttribute(string name)
void Reset(XmlReader reader)
ValidatingReaderNodeData _textNode
XsdCachingReader(XmlReader reader, IXmlLineInfo lineInfo, CachingEventHandler handlerMethod)
readonly CachingEventHandler _cacheHandler
CachingReaderState _cacheState
override bool MoveToAttribute(string name, string ns)
readonly IXmlLineInfo _lineInfo
override async Task SkipAsync()
override string GetAttribute(string name, string namespaceURI)
override string GetAttribute(string name)
ValidatingReaderNodeData RecordTextNode(string textValue, string originalStringValue, int depth, int lineNo, int linePos)
ValidatingReaderNodeData AddAttribute(int attIndex)
override XmlReaderSettings Settings
int GetAttributeIndexWithPrefix(string name)
ValidatingReaderNodeData _cachedNode
override string LookupNamespace(string prefix)
int GetAttributeIndexWithoutPrefix(string name)
ValidatingReaderNodeData[] _contentEvents
void SwitchTextNodeAndEndElement(string textValue, string originalStringValue)
ValidatingReaderNodeData[] _attributeEvents
override XmlNodeType NodeType
override string GetAttribute(int i)
override void MoveToAttribute(int i)
ValidatingReaderNodeData CreateDummyTextNode(string attributeValue, int depth)
delegate void CachingEventHandler(XsdCachingReader cachingReader)