Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ParseXmlDeclarationAsync()

async Task< bool > System.Xml.XmlTextReaderImpl.ParseXmlDeclarationAsync ( bool isTextDecl)
inlineprivate

Definition at line 9514 of file XmlTextReaderImpl.cs.

9515 {
9516 do
9517 {
9518 if (_ps.charsUsed - _ps.charPos < 6)
9519 {
9520 continue;
9521 }
9522 if (!XmlConvert.StrEqual(_ps.chars, _ps.charPos, 5, "<?xml") || XmlCharType.IsNameSingleChar(_ps.chars[_ps.charPos + 5]))
9523 {
9524 break;
9525 }
9526 if (!isTextDecl)
9527 {
9529 _curNode.SetNamedNode(XmlNodeType.XmlDeclaration, _xml);
9530 }
9531 _ps.charPos += 5;
9533 int xmlDeclState = 0;
9534 Encoding encoding = null;
9535 while (true)
9536 {
9537 int originalSbLen = sb.Length;
9538 int num = await EatWhitespacesAsync((xmlDeclState == 0) ? null : sb).ConfigureAwait(continueOnCapturedContext: false);
9539 if (_ps.chars[_ps.charPos] == '?')
9540 {
9542 if (_ps.chars[_ps.charPos + 1] == '>')
9543 {
9544 break;
9545 }
9546 if (_ps.charPos + 1 == _ps.charsUsed)
9547 {
9548 goto IL_0cb2;
9549 }
9550 ThrowUnexpectedToken("'>'");
9551 }
9552 if (num == 0 && xmlDeclState != 0)
9553 {
9555 }
9556 int num2 = await ParseNameAsync().ConfigureAwait(continueOnCapturedContext: false);
9557 NodeData attr = null;
9558 char c = _ps.chars[_ps.charPos];
9559 if (c != 'e')
9560 {
9561 if (c != 's')
9562 {
9563 if (c != 'v' || !XmlConvert.StrEqual(_ps.chars, _ps.charPos, num2 - _ps.charPos, "version") || xmlDeclState != 0)
9564 {
9565 goto IL_06a6;
9566 }
9567 if (!isTextDecl)
9568 {
9569 attr = AddAttributeNoChecks("version", 1);
9570 }
9571 }
9572 else
9573 {
9574 if (!XmlConvert.StrEqual(_ps.chars, _ps.charPos, num2 - _ps.charPos, "standalone") || (xmlDeclState != 1 && xmlDeclState != 2) || isTextDecl)
9575 {
9576 goto IL_06a6;
9577 }
9578 if (!isTextDecl)
9579 {
9580 attr = AddAttributeNoChecks("standalone", 1);
9581 }
9582 xmlDeclState = 2;
9583 }
9584 }
9585 else
9586 {
9587 if (!XmlConvert.StrEqual(_ps.chars, _ps.charPos, num2 - _ps.charPos, "encoding") || (xmlDeclState != 1 && (!isTextDecl || xmlDeclState != 0)))
9588 {
9589 goto IL_06a6;
9590 }
9591 if (!isTextDecl)
9592 {
9593 attr = AddAttributeNoChecks("encoding", 1);
9594 }
9595 xmlDeclState = 1;
9596 }
9597 goto IL_06c0;
9598 IL_06c0:
9599 if (!isTextDecl)
9600 {
9601 attr.SetLineInfo(_ps.LineNo, _ps.LinePos);
9602 }
9604 _ps.charPos = num2;
9605 if (_ps.chars[_ps.charPos] != '=')
9606 {
9608 if (_ps.chars[_ps.charPos] != '=')
9609 {
9611 }
9612 }
9613 sb.Append('=');
9614 _ps.charPos++;
9615 char quoteChar = _ps.chars[_ps.charPos];
9616 if (quoteChar != '"' && quoteChar != '\'')
9617 {
9619 quoteChar = _ps.chars[_ps.charPos];
9620 if (quoteChar != '"' && quoteChar != '\'')
9621 {
9622 ThrowUnexpectedToken("\"", "'");
9623 }
9624 }
9625 sb.Append(quoteChar);
9626 _ps.charPos++;
9627 if (!isTextDecl)
9628 {
9629 attr.quoteChar = quoteChar;
9630 attr.SetLineInfo2(_ps.LineNo, _ps.LinePos);
9631 }
9632 int pos = _ps.charPos;
9633 char[] chars;
9634 while (true)
9635 {
9636 for (chars = _ps.chars; XmlCharType.IsAttributeValueChar(chars[pos]); pos++)
9637 {
9638 }
9639 if (_ps.chars[pos] == quoteChar)
9640 {
9641 break;
9642 }
9643 if (pos == _ps.charsUsed)
9644 {
9645 if (await ReadDataAsync().ConfigureAwait(continueOnCapturedContext: false) != 0)
9646 {
9647 continue;
9648 }
9649 goto IL_0c8b;
9650 }
9651 goto IL_0c98;
9652 }
9653 switch (xmlDeclState)
9654 {
9655 case 0:
9656 if (XmlConvert.StrEqual(_ps.chars, _ps.charPos, pos - _ps.charPos, "1.0"))
9657 {
9658 if (!isTextDecl)
9659 {
9660 attr.SetValue(_ps.chars, _ps.charPos, pos - _ps.charPos);
9661 }
9662 xmlDeclState = 1;
9663 }
9664 else
9665 {
9666 string arg = new string(_ps.chars, _ps.charPos, pos - _ps.charPos);
9668 }
9669 break;
9670 case 1:
9671 {
9672 string text = new string(_ps.chars, _ps.charPos, pos - _ps.charPos);
9673 encoding = CheckEncoding(text);
9674 if (!isTextDecl)
9675 {
9676 attr.SetValue(text);
9677 }
9678 xmlDeclState = 2;
9679 break;
9680 }
9681 case 2:
9682 if (XmlConvert.StrEqual(_ps.chars, _ps.charPos, pos - _ps.charPos, "yes"))
9683 {
9684 _standalone = true;
9685 }
9686 else if (XmlConvert.StrEqual(_ps.chars, _ps.charPos, pos - _ps.charPos, "no"))
9687 {
9688 _standalone = false;
9689 }
9690 else
9691 {
9693 }
9694 if (!isTextDecl)
9695 {
9696 attr.SetValue(_ps.chars, _ps.charPos, pos - _ps.charPos);
9697 }
9698 xmlDeclState = 3;
9699 break;
9700 }
9701 sb.Append(chars, _ps.charPos, pos - _ps.charPos);
9702 sb.Append(quoteChar);
9703 _ps.charPos = pos + 1;
9704 continue;
9705 IL_0cb2:
9706 bool isEof = _ps.isEof;
9707 bool flag = isEof;
9708 if (!flag)
9709 {
9710 flag = await ReadDataAsync().ConfigureAwait(continueOnCapturedContext: false) == 0;
9711 }
9712 if (flag)
9713 {
9715 }
9716 continue;
9717 IL_0c98:
9718 Throw(isTextDecl ? System.SR.Xml_InvalidTextDecl : System.SR.Xml_InvalidXmlDecl);
9719 goto IL_0cb2;
9720 IL_0c8b:
9722 goto IL_0cb2;
9723 IL_06a6:
9724 Throw(isTextDecl ? System.SR.Xml_InvalidTextDecl : System.SR.Xml_InvalidXmlDecl);
9725 goto IL_06c0;
9726 }
9727 if (xmlDeclState == 0)
9728 {
9729 Throw(isTextDecl ? System.SR.Xml_InvalidTextDecl : System.SR.Xml_InvalidXmlDecl);
9730 }
9731 _ps.charPos += 2;
9732 if (!isTextDecl)
9733 {
9735 sb.Length = 0;
9737 _parsingFunction = ParsingFunction.ResetAttributesRootLevel;
9738 }
9739 if (encoding != null)
9740 {
9742 }
9743 else
9744 {
9745 if (isTextDecl)
9746 {
9748 }
9749 if (_afterResetState)
9750 {
9751 string webName = _ps.encoding.WebName;
9752 if (webName != "utf-8" && webName != "utf-16" && webName != "utf-16BE" && !(_ps.encoding is Ucs4Encoding))
9753 {
9754 Throw(System.SR.Xml_EncodingSwitchAfterResetState, (_ps.encoding.GetByteCount("A") == 1) ? "UTF-8" : "UTF-16");
9755 }
9756 }
9757 if (_ps.decoder is SafeAsciiDecoder)
9758 {
9760 }
9761 }
9762 _ps.appendMode = false;
9763 return true;
9764 }
9765 while (await ReadDataAsync().ConfigureAwait(continueOnCapturedContext: false) != 0);
9766 if (!isTextDecl)
9767 {
9769 }
9770 if (_afterResetState)
9771 {
9772 string webName2 = _ps.encoding.WebName;
9773 if (webName2 != "utf-8" && webName2 != "utf-16" && webName2 != "utf-16BE" && !(_ps.encoding is Ucs4Encoding))
9774 {
9775 Throw(System.SR.Xml_EncodingSwitchAfterResetState, (_ps.encoding.GetByteCount("A") == 1) ? "UTF-8" : "UTF-16");
9776 }
9777 }
9778 if (_ps.decoder is SafeAsciiDecoder)
9779 {
9781 }
9782 _ps.appendMode = false;
9783 return false;
9784 }
static string Xml_UnexpectedEOF1
Definition SR.cs:38
static string Xml_UnclosedQuote
Definition SR.cs:34
static string Xml_InvalidXmlDecl
Definition SR.cs:86
static string Xml_EncodingSwitchAfterResetState
Definition SR.cs:234
static string Xml_InvalidVersionNumber
Definition SR.cs:94
static string Xml_InvalidTextDecl
Definition SR.cs:116
Definition SR.cs:7
virtual string WebName
Definition Encoding.cs:386
virtual int GetByteCount(char[] chars)
Definition Encoding.cs:713
override string ToString()
StringBuilder Append(char value, int repeatCount)
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)
Definition Task.cs:226
void SetLineInfo(int lineNo, int linePos)
void SetNamedNode(XmlNodeType type, string localName)
readonly StringBuilder _stringBuilder
Task SwitchEncodingAsync(Encoding newEncoding)
Encoding CheckEncoding(string newEncodingName)
NodeData AddAttributeNoChecks(string name, int attrDepth)
async Task< int > EatWhitespacesAsync(StringBuilder sb)
void Throw(int pos, string res, string arg)
void ThrowUnexpectedToken(int pos, string expectedToken)

References System.Xml.XmlTextReaderImpl._afterResetState, System.Xml.XmlTextReaderImpl._curNode, System.Xml.XmlTextReaderImpl._nextParsingFunction, System.Xml.XmlTextReaderImpl._parsingFunction, System.Xml.XmlTextReaderImpl._ps, System.Xml.XmlTextReaderImpl._standalone, System.Xml.XmlTextReaderImpl._stringBuilder, System.Xml.XmlTextReaderImpl._xml, System.Xml.XmlTextReaderImpl.AddAttributeNoChecks(), System.Text.StringBuilder.Append(), System.Xml.XmlTextReaderImpl.ParsingState.charPos, System.chars, System.Xml.XmlTextReaderImpl.ParsingState.chars, System.Xml.XmlTextReaderImpl.ParsingState.charsUsed, System.Xml.XmlTextReaderImpl.CheckEncoding(), System.Threading.Tasks.Task< TResult >.ConfigureAwait(), System.Xml.XmlTextReaderImpl.ParsingState.decoder, System.Xml.Dictionary, System.Xml.XmlTextReaderImpl.EatWhitespacesAsync(), System.Xml.XmlTextReaderImpl.ParsingState.encoding, System.Text.Encoding.GetByteCount(), System.Xml.XmlCharType.IsAttributeValueChar(), System.Xml.XmlTextReaderImpl.ParsingState.isEof, System.Xml.XmlCharType.IsNameSingleChar(), System.Text.StringBuilder.Length, System.Xml.XmlTextReaderImpl.ParsingState.LineNo, System.Xml.XmlTextReaderImpl.ParsingState.LinePos, System.Xml.XmlTextReaderImpl.ParseNameAsync(), System.Xml.XmlTextReaderImpl.ReadDataAsync(), System.Xml.XmlTextReaderImpl.NodeData.SetLineInfo(), System.Xml.XmlTextReaderImpl.NodeData.SetNamedNode(), System.Xml.XmlTextReaderImpl.NodeData.SetValue(), System.Xml.XmlConvert.StrEqual(), System.Xml.XmlTextReaderImpl.SwitchEncodingAsync(), System.Xml.XmlTextReaderImpl.SwitchEncodingToUTF8Async(), System.text, System.Xml.XmlTextReaderImpl.Throw(), System.Xml.XmlTextReaderImpl.ThrowUnexpectedToken(), System.Text.StringBuilder.ToString(), System.Text.Encoding.WebName, System.SR.Xml_EncodingSwitchAfterResetState, System.SR.Xml_InvalidTextDecl, System.SR.Xml_InvalidVersionNumber, System.SR.Xml_InvalidXmlDecl, System.SR.Xml_UnclosedQuote, and System.SR.Xml_UnexpectedEOF1.

Referenced by System.Xml.XmlTextReaderImpl.DtdParserProxy_PushExternalSubsetAsync(), System.Xml.XmlTextReaderImpl.PushExternalEntityAsync(), and System.Xml.XmlTextReaderImpl.ReadAsync_SwitchToInteractiveXmlDecl().