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

◆ ParseXmlDeclaration()

bool System.Xml.XmlTextReaderImpl.ParseXmlDeclaration ( bool isTextDecl)
inlineprivate

Definition at line 3635 of file XmlTextReaderImpl.cs.

3636 {
3637 do
3638 {
3639 if (_ps.charsUsed - _ps.charPos < 6)
3640 {
3641 continue;
3642 }
3643 if (!XmlConvert.StrEqual(_ps.chars, _ps.charPos, 5, "<?xml") || XmlCharType.IsNameSingleChar(_ps.chars[_ps.charPos + 5]))
3644 {
3645 break;
3646 }
3647 if (!isTextDecl)
3648 {
3650 _curNode.SetNamedNode(XmlNodeType.XmlDeclaration, _xml);
3651 }
3652 _ps.charPos += 5;
3654 int num = 0;
3655 Encoding encoding = null;
3656 while (true)
3657 {
3658 int length = stringBuilder.Length;
3659 int num2 = EatWhitespaces((num == 0) ? null : stringBuilder);
3660 if (_ps.chars[_ps.charPos] == '?')
3661 {
3663 if (_ps.chars[_ps.charPos + 1] == '>')
3664 {
3665 break;
3666 }
3667 if (_ps.charPos + 1 == _ps.charsUsed)
3668 {
3669 goto IL_07a5;
3670 }
3671 ThrowUnexpectedToken("'>'");
3672 }
3673 if (num2 == 0 && num != 0)
3674 {
3676 }
3677 int num3 = ParseName();
3678 NodeData nodeData = null;
3679 char c = _ps.chars[_ps.charPos];
3680 if (c != 'e')
3681 {
3682 if (c != 's')
3683 {
3684 if (c != 'v' || !XmlConvert.StrEqual(_ps.chars, _ps.charPos, num3 - _ps.charPos, "version") || num != 0)
3685 {
3686 goto IL_03af;
3687 }
3688 if (!isTextDecl)
3689 {
3690 nodeData = AddAttributeNoChecks("version", 1);
3691 }
3692 }
3693 else
3694 {
3695 if (!XmlConvert.StrEqual(_ps.chars, _ps.charPos, num3 - _ps.charPos, "standalone") || (num != 1 && num != 2) || isTextDecl)
3696 {
3697 goto IL_03af;
3698 }
3699 if (!isTextDecl)
3700 {
3701 nodeData = AddAttributeNoChecks("standalone", 1);
3702 }
3703 num = 2;
3704 }
3705 }
3706 else
3707 {
3708 if (!XmlConvert.StrEqual(_ps.chars, _ps.charPos, num3 - _ps.charPos, "encoding") || (num != 1 && (!isTextDecl || num != 0)))
3709 {
3710 goto IL_03af;
3711 }
3712 if (!isTextDecl)
3713 {
3714 nodeData = AddAttributeNoChecks("encoding", 1);
3715 }
3716 num = 1;
3717 }
3718 goto IL_03c4;
3719 IL_03c4:
3720 if (!isTextDecl)
3721 {
3722 nodeData.SetLineInfo(_ps.LineNo, _ps.LinePos);
3723 }
3725 _ps.charPos = num3;
3726 if (_ps.chars[_ps.charPos] != '=')
3727 {
3729 if (_ps.chars[_ps.charPos] != '=')
3730 {
3732 }
3733 }
3734 stringBuilder.Append('=');
3735 _ps.charPos++;
3736 char c2 = _ps.chars[_ps.charPos];
3737 if (c2 != '"' && c2 != '\'')
3738 {
3740 c2 = _ps.chars[_ps.charPos];
3741 if (c2 != '"' && c2 != '\'')
3742 {
3743 ThrowUnexpectedToken("\"", "'");
3744 }
3745 }
3746 stringBuilder.Append(c2);
3747 _ps.charPos++;
3748 if (!isTextDecl)
3749 {
3751 nodeData.SetLineInfo2(_ps.LineNo, _ps.LinePos);
3752 }
3753 int i = _ps.charPos;
3754 char[] chars;
3755 while (true)
3756 {
3757 for (chars = _ps.chars; XmlCharType.IsAttributeValueChar(chars[i]); i++)
3758 {
3759 }
3760 if (_ps.chars[i] == c2)
3761 {
3762 break;
3763 }
3764 if (i == _ps.charsUsed)
3765 {
3766 if (ReadData() != 0)
3767 {
3768 continue;
3769 }
3770 goto IL_0783;
3771 }
3772 goto IL_0790;
3773 }
3774 switch (num)
3775 {
3776 case 0:
3777 if (XmlConvert.StrEqual(_ps.chars, _ps.charPos, i - _ps.charPos, "1.0"))
3778 {
3779 if (!isTextDecl)
3780 {
3781 nodeData.SetValue(_ps.chars, _ps.charPos, i - _ps.charPos);
3782 }
3783 num = 1;
3784 }
3785 else
3786 {
3787 string arg = new string(_ps.chars, _ps.charPos, i - _ps.charPos);
3789 }
3790 break;
3791 case 1:
3792 {
3793 string text = new string(_ps.chars, _ps.charPos, i - _ps.charPos);
3794 encoding = CheckEncoding(text);
3795 if (!isTextDecl)
3796 {
3797 nodeData.SetValue(text);
3798 }
3799 num = 2;
3800 break;
3801 }
3802 case 2:
3803 if (XmlConvert.StrEqual(_ps.chars, _ps.charPos, i - _ps.charPos, "yes"))
3804 {
3805 _standalone = true;
3806 }
3807 else if (XmlConvert.StrEqual(_ps.chars, _ps.charPos, i - _ps.charPos, "no"))
3808 {
3809 _standalone = false;
3810 }
3811 else
3812 {
3814 }
3815 if (!isTextDecl)
3816 {
3817 nodeData.SetValue(_ps.chars, _ps.charPos, i - _ps.charPos);
3818 }
3819 num = 3;
3820 break;
3821 }
3822 stringBuilder.Append(chars, _ps.charPos, i - _ps.charPos);
3823 stringBuilder.Append(c2);
3824 _ps.charPos = i + 1;
3825 continue;
3826 IL_07a5:
3827 if (_ps.isEof || ReadData() == 0)
3828 {
3830 }
3831 continue;
3832 IL_0790:
3833 Throw(isTextDecl ? System.SR.Xml_InvalidTextDecl : System.SR.Xml_InvalidXmlDecl);
3834 goto IL_07a5;
3835 IL_0783:
3837 goto IL_07a5;
3838 IL_03af:
3839 Throw(isTextDecl ? System.SR.Xml_InvalidTextDecl : System.SR.Xml_InvalidXmlDecl);
3840 goto IL_03c4;
3841 }
3842 if (num == 0)
3843 {
3844 Throw(isTextDecl ? System.SR.Xml_InvalidTextDecl : System.SR.Xml_InvalidXmlDecl);
3845 }
3846 _ps.charPos += 2;
3847 if (!isTextDecl)
3848 {
3849 _curNode.SetValue(stringBuilder.ToString());
3852 _parsingFunction = ParsingFunction.ResetAttributesRootLevel;
3853 }
3854 if (encoding == null)
3855 {
3856 if (isTextDecl)
3857 {
3859 }
3860 if (_afterResetState)
3861 {
3862 string webName = _ps.encoding.WebName;
3863 if (webName != "utf-8" && webName != "utf-16" && webName != "utf-16BE" && !(_ps.encoding is Ucs4Encoding))
3864 {
3865 Throw(System.SR.Xml_EncodingSwitchAfterResetState, (_ps.encoding.GetByteCount("A") == 1) ? "UTF-8" : "UTF-16");
3866 }
3867 }
3868 if (_ps.decoder is SafeAsciiDecoder)
3869 {
3871 }
3872 }
3873 else
3874 {
3875 SwitchEncoding(encoding);
3876 }
3877 _ps.appendMode = false;
3878 return true;
3879 }
3880 while (ReadData() != 0);
3881 if (!isTextDecl)
3882 {
3884 }
3885 if (_afterResetState)
3886 {
3887 string webName2 = _ps.encoding.WebName;
3888 if (webName2 != "utf-8" && webName2 != "utf-16" && webName2 != "utf-16BE" && !(_ps.encoding is Ucs4Encoding))
3889 {
3890 Throw(System.SR.Xml_EncodingSwitchAfterResetState, (_ps.encoding.GetByteCount("A") == 1) ? "UTF-8" : "UTF-16");
3891 }
3892 }
3893 if (_ps.decoder is SafeAsciiDecoder)
3894 {
3896 }
3897 _ps.appendMode = false;
3898 return false;
3899 }
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
void SetLineInfo(int lineNo, int linePos)
void SetNamedNode(XmlNodeType type, string localName)
readonly StringBuilder _stringBuilder
Encoding CheckEncoding(string newEncodingName)
NodeData AddAttributeNoChecks(string name, int attrDepth)
int EatWhitespaces(StringBuilder sb)
void SwitchEncoding(Encoding newEncoding)
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.Xml.XmlTextReaderImpl.ParsingState.charPos, System.chars, System.Xml.XmlTextReaderImpl.ParsingState.chars, System.Xml.XmlTextReaderImpl.ParsingState.charsUsed, System.Xml.XmlTextReaderImpl.CheckEncoding(), System.Xml.XmlTextReaderImpl.ParsingState.decoder, System.Xml.Dictionary, System.Xml.XmlTextReaderImpl.EatWhitespaces(), System.Xml.XmlTextReaderImpl.ParsingState.encoding, System.Text.Encoding.GetByteCount(), System.Xml.XmlCharType.IsAttributeValueChar(), System.Xml.XmlTextReaderImpl.ParsingState.isEof, System.Xml.XmlCharType.IsNameSingleChar(), System.length, System.Xml.XmlTextReaderImpl.ParsingState.LineNo, System.Xml.XmlTextReaderImpl.ParsingState.LinePos, System.Xml.XmlTextReaderImpl.ParseName(), System.Xml.XmlTextReaderImpl.ReadData(), System.Xml.XmlTextReaderImpl.NodeData.SetLineInfo(), System.Xml.XmlTextReaderImpl.NodeData.SetNamedNode(), System.Xml.XmlTextReaderImpl.NodeData.SetValue(), System.Xml.XmlConvert.StrEqual(), System.Xml.XmlTextReaderImpl.SwitchEncoding(), System.Xml.XmlTextReaderImpl.SwitchEncodingToUTF8(), System.text, System.Xml.XmlTextReaderImpl.Throw(), System.Xml.XmlTextReaderImpl.ThrowUnexpectedToken(), 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_PushExternalSubset(), System.Xml.XmlTextReaderImpl.ParseXmlDeclarationFragment(), System.Xml.XmlTextReaderImpl.PushExternalEntity(), and System.Xml.XmlTextReaderImpl.Read().