private Token GetNextToken(bool stopAtEndOfLine) { this.isWhitespace = false; switch (this.state) { case Scanner.State.StringLiteral1: case Scanner.State.StringLiteral2: if (this.endPos >= this.maxPos) { if (!stopAtEndOfLine) { this.HandleError(this.beginBlock, SR.UnclosedString, new string[0]); } return(Token.EndOfFile); } Token token1; if ((int)this.GetChar(this.endPos) == 38) { this.isWhitespace = false; token1 = this.ScanEntityReference(); } else { token1 = this.ScanXmlString(this.state == Scanner.State.StringLiteral1 ? '"' : '\'', true); if (this.stillInsideMultiLineToken) { this.stillInsideMultiLineToken = false; } else { this.state = Scanner.State.Attributes; } } return(token1); case Scanner.State.Text: if (this.endPos >= this.maxPos) { return(Token.EndOfFile); } Token token2; if ((int)this.GetChar(this.endPos) == 38) { token2 = this.ScanEntityReference(); } else { token2 = this.ScanXmlText(stopAtEndOfLine); if (this.stillInsideMultiLineToken) { this.stillInsideMultiLineToken = false; } else { this.state = Scanner.State.Xml; } } return(token2); case Scanner.State.LiteralComment: if (this.endPos >= this.maxPos) { if (!stopAtEndOfLine) { this.HandleError(this.beginBlock, SR.UnclosedComment, new string[0]); } return(Token.EndOfFile); } Token token3 = this.ScanXmlComment(stopAtEndOfLine); if (this.stillInsideMultiLineToken) { this.stillInsideMultiLineToken = false; } else { this.state = Scanner.State.Xml; } return(token3); case Scanner.State.Xml: if (this.endPos >= this.maxPos) { return(Token.EndOfFile); } this.startPos = this.endPos; if (this.mode == Scanner.State.InternalSubset) { this.SkipWhitespace(); if (this.startPos < this.endPos) { this.unescapedString = this.Substring(this.startPos, this.endPos - this.startPos); this.isWhitespace = true; return(Token.LiteralContentString); } if ((int)this.GetChar(this.endPos) == 93 && this.mode == Scanner.State.InternalSubset) { ++this.endPos; this.mode = Scanner.State.Xml; this.state = Scanner.State.Tag; return(Token.RightBracket); } } if ((int)this.GetChar(this.endPos) == 38) { return(this.ScanEntityReference()); } Token token4 = this.ScanXmlText(stopAtEndOfLine); if (this.startPos < this.endPos) { this.state = (int)this.GetChar(this.endPos) != 60 ? Scanner.State.Text : Scanner.State.Tag; return(token4); } this.isWhitespace = false; break; case Scanner.State.CData: if (this.endPos >= this.maxPos) { if (!stopAtEndOfLine) { this.HandleError(this.beginBlock, SR.UnclosedCData, new string[0]); } return(Token.EndOfFile); } Token token5 = this.ScanXmlCharacterData(stopAtEndOfLine); if (this.stillInsideMultiLineToken) { this.stillInsideMultiLineToken = false; } else { this.state = Scanner.State.Xml; } return(token5); case Scanner.State.PI: if (this.endPos >= this.maxPos) { if (!stopAtEndOfLine) { this.HandleError(this.beginBlock, SR.UnclosedPI, new string[0]); } return(Token.EndOfFile); } Token token6 = this.ScanXmlProcessingInstructionsTag(stopAtEndOfLine); if (this.stillInsideMultiLineToken) { this.stillInsideMultiLineToken = false; if (token6 == Token.Identifier && this.unescapedString == "xml") { this.state = Scanner.State.Tag; } } else { this.state = Scanner.State.Xml; } return(token6); } this.startPos = this.endPos; char char1 = this.GetChar(this.endPos++); switch (char1) { case ':': this.unescapedString = ":"; return(Token.Colon); case '<': char char2 = this.GetChar(this.endPos); switch (char2) { case '/': this.GetChar(++this.endPos); this.state = Scanner.State.EndTag; this.unescapedString = "</"; return(Token.StartOfClosingTag); case '?': ++this.endPos; this.beginBlock = this.CurrentSourceContext; this.state = Scanner.State.PI; this.unescapedString = this.Substring(this.startPos, this.endPos - this.startPos); return(Token.StartProcessingInstruction); case '!': char char3 = this.GetChar(++this.endPos); switch (char3) { case '-': if ((int)this.GetChar(++this.endPos) == 45) { ++this.endPos; this.beginBlock = this.CurrentSourceContext; this.state = Scanner.State.LiteralComment; this.unescapedString = this.Substring(this.startPos, this.endPos - this.startPos); return(Token.StartLiteralComment); } --this.endPos; --this.endPos; break; case '[': if ((int)this.GetChar(this.endPos + 1) == 67 && (int)this.GetChar(this.endPos + 2) == 68 && ((int)this.GetChar(this.endPos + 3) == 65 && (int)this.GetChar(this.endPos + 4) == 84) && ((int)this.GetChar(this.endPos + 5) == 65 && (int)this.GetChar(this.endPos + 6) == 91)) { this.endPos += 7; this.beginBlock = this.CurrentSourceContext; this.state = Scanner.State.CData; this.unescapedString = this.Substring(this.startPos, this.endPos - this.startPos); return(Token.StartCharacterData); } this.unescapedString = this.Substring(this.startPos, this.endPos - this.startPos); this.state = Scanner.State.Xml; this.HandleError(SR.ExpectingToken, "CDATA["); return(Token.IllegalCharacter); default: if (XmlCharType.IsStartNameChar(char3)) { this.state = Scanner.State.Tag; this.unescapedString = "<!"; if (this.mode != Scanner.State.InternalSubset) { this.mode = Scanner.State.DocType; } return(Token.MarkupDeclaration); } this.unescapedString = char3.ToString(); this.HandleError(SR.ExpectingToken, "DOCTYPE"); this.state = Scanner.State.Xml; return(Token.IllegalCharacter); } break; default: if (!XmlCharType.IsStartNameChar(char2)) { this.HandleError(SR.ExpectingTagName); this.state = Scanner.State.Xml; break; } this.unescapedString = "<"; this.state = Scanner.State.Tag; break; } return(Token.StartOfTag); case '=': this.state = Scanner.State.Attributes; this.unescapedString = "="; return(Token.Assign); case '>': this.unescapedString = ">"; Token token7 = this.state == Scanner.State.EndTag ? Token.EndOfEndTag : Token.EndOfTag; this.state = Scanner.State.Xml; if (this.mode == Scanner.State.DocType) { this.mode = Scanner.State.Xml; } return(token7); case '?': if ((int)this.GetChar(this.endPos) == 62) { ++this.endPos; this.unescapedString = "?>"; this.state = Scanner.State.Xml; return(Token.EndOfTag); } break; case '[': this.unescapedString = "["; this.mode = Scanner.State.InternalSubset; return(Token.LeftBracket); case ']': this.unescapedString = "]"; if ((int)this.GetChar(this.endPos) == 62) { this.unescapedString = "]"; this.state = Scanner.State.Tag; this.mode = Scanner.State.Xml; } return(Token.RightBracket); case '\'': case '"': this.LiteralQuoteChar = char1; this.unescapedString = char1.ToString(); this.state = (int)char1 == 34 ? Scanner.State.StringLiteral1 : Scanner.State.StringLiteral2; this.beginBlock = this.CurrentSourceContext; return(Token.StartStringLiteral); case '/': if ((int)this.GetChar(this.endPos) != 62) { return(Token.StringLiteral); } this.unescapedString = "/>"; ++this.endPos; this.state = Scanner.State.Xml; return(Token.EndOfSimpleTag); case char.MinValue: this.startPos = this.endPos; return(Token.EndOfFile); case '\t': case '\n': case '\r': case ' ': this.SkipWhitespace(); if (this.state != Scanner.State.EndTag) { this.state = Scanner.State.Attributes; } return(Token.Whitespace); } if (this.mode == Scanner.State.InternalSubset) { switch (char1) { case '#': this.unescapedString = "#"; return(Token.Pound); case '%': this.unescapedString = "%"; return(Token.Percent); case '(': this.unescapedString = "("; return(Token.LeftParen); case ')': this.unescapedString = ")"; return(Token.RightParen); case '*': this.unescapedString = "*"; return(Token.Star); case '+': this.unescapedString = "+"; return(Token.Plus); case ',': this.unescapedString = ","; return(Token.Comma); case '?': this.unescapedString = "?"; return(Token.QuestionMark); case '|': this.unescapedString = "|"; return(Token.Or); } } if (XmlCharType.IsNameChar(char1)) { --this.endPos; if (this.mode == Scanner.State.InternalSubset || this.mode == Scanner.State.DocType) { Token token8 = this.ScanKeyword(); if (token8 != Token.Identifier) { return(token8); } } this.ScanName(); if (this.lastToken != Token.Colon) { this.isXslKeyword = this.IsXslKeyword(); } return(Token.Identifier); } this.unescapedString = char1.ToString(); this.HandleError(SR.IllegalNameCharacter, new string[2] { char1.ToString(), Convert.ToInt32(char1).ToString() }); return(Token.IllegalCharacter); }
private Token ScanXmlComment(bool stopAtEndOfLine) { int start = this.endPos; this.startPos = this.endPos; char char1; char char2; while (true) { char1 = this.GetChar(this.endPos); if ((int)char1 >= 55296 && (int)char1 <= 56319) { char2 = this.GetChar(this.endPos + 1); if ((int)char2 >= 56320 && (int)char2 <= 57343) { this.endPos += 2; } else { break; } } else if (XmlCharType.IsCharData(char1)) { while ((int)char1 == 45) { char1 = this.GetChar(++this.endPos); if ((int)char1 == 45) { char1 = this.GetChar(++this.endPos); if ((int)char1 == 62) { if (this.endPos > start + 3) { this.endPos -= 2; this.unescapedString = this.Substring(start, this.endPos - start); this.stillInsideMultiLineToken = true; return(Token.LiteralComment); } ++this.endPos; this.unescapedString = "-->"; this.state = Scanner.State.Xml; return(Token.EndOfTag); } if ((int)char1 != 0) { if (this.endPos > start + 2) { this.endPos -= 2; this.unescapedString = this.Substring(start, this.endPos - start); this.stillInsideMultiLineToken = true; return(Token.LiteralComment); } this.unescapedString = this.Substring(start, this.endPos - start); this.stillInsideMultiLineToken = true; this.HandleError(SR.IllegalComment, this.unescapedString); return(Token.IllegalCharacter); } if ((int)char1 == 0 && this.endPos >= this.maxPos) { return(Token.LiteralComment); } } else if ((int)char1 == 0 && this.endPos >= this.maxPos) { if (stopAtEndOfLine) { this.stillInsideMultiLineToken = true; } return(Token.LiteralComment); } } if ((int)char1 != 0 || this.endPos < this.maxPos) { ++this.endPos; } else { goto label_24; } } else { goto label_6; } } return(this.HandleIllegalSurrogatePair(char1, char2, Token.LiteralComment)); label_6: return(this.HandleIllegalCharacter(char1, Token.LiteralComment)); label_24: if (stopAtEndOfLine) { this.stillInsideMultiLineToken = true; } return(Token.LiteralComment); }
private Token ScanXmlString(char closingQuote, bool stopAtEndOfLine) { this.startPos = this.endPos; this.unescapedString = (string)null; this.isWhitespace = false; char char1 = this.GetChar(this.endPos); if ((int)char1 >= 55296 && (int)char1 <= 56319) { char char2 = this.GetChar(this.endPos + 1); if ((int)char2 < 56320 || (int)char2 > 57343) { this.stillInsideMultiLineToken = true; if (this.endPos < this.maxPos) { ++this.endPos; } this.HandleError(SR.IllegalSurrogatePair, new string[2] { Convert.ToInt32(char1).ToString("x"), Convert.ToInt32(char2).ToString("x") }); return(Token.IllegalCharacter); } this.endPos += 2; } else { if (!XmlCharType.IsCharData(char1)) { this.stillInsideMultiLineToken = true; ++this.endPos; this.unescapedString = char1.ToString(); this.HandleError(SR.IllegalCharacter, new string[2] { char1.ToString(), Convert.ToInt32(char1).ToString() }); return(Token.IllegalCharacter); } if ((int)char1 == 60 && this.mode != Scanner.State.InternalSubset) { ++this.endPos; this.unescapedString = char1.ToString(); this.HandleError(SR.IllegalAttributeCharacter, new string[2] { char1.ToString(), Convert.ToInt32(char1).ToString() }); --this.endPos; return(Token.IllegalCharacter); } } char char3; do { char3 = this.GetChar(this.endPos++); if ((int)char3 >= 55296 && (int)char3 <= 56319) { char char2 = this.GetChar(this.endPos++); if ((int)char2 < 56320 || (int)char2 > 57343) { this.stillInsideMultiLineToken = true; break; } } else { if (!XmlCharType.IsCharData(char3)) { this.stillInsideMultiLineToken = true; break; } if ((int)char3 == 60 && this.mode != Scanner.State.InternalSubset) { this.stillInsideMultiLineToken = true; break; } if ((int)char3 == 38) { this.stillInsideMultiLineToken = true; break; } if ((int)char3 == 0 && this.endPos >= this.maxPos) { if (stopAtEndOfLine) { this.stillInsideMultiLineToken = true; } --this.endPos; break; } } }while ((int)char3 != (int)closingQuote); this.unescapedString = this.endPos > this.startPos + 1 ? this.Substring(this.startPos, this.endPos - this.startPos - 1) : ""; if ((int)char3 != (int)closingQuote) { --this.endPos; } this.isWhitespace = false; return(Token.StringLiteral); }
internal bool ScanNamespaceSeparator() { if (this.endPos >= this.maxPos - 2 || (int)this.GetChar(this.endPos) != 58 || !XmlCharType.IsStartNameChar(this.GetChar(this.endPos + 1))) { return(false); } this.startPos = this.endPos; ++this.endPos; return(true); }
private Token ScanXmlText(bool stopAtEndOfLine) { int num = this.endPos; this.startPos = this.endPos; this.unescapedString = (string)null; this.isWhitespace = true; char char1; while (true) { do { char1 = this.GetChar(this.endPos++); if ((int)char1 == 38) { this.stillInsideMultiLineToken = true; goto label_15; } else if ((int)char1 == 0 && this.endPos >= this.maxPos) { if (stopAtEndOfLine) { this.stillInsideMultiLineToken = true; goto label_15; } else { goto label_15; } } else if ((int)char1 >= 55296 && (int)char1 <= 56319) { char char2 = this.GetChar(this.endPos); if ((int)char2 < 56320 || (int)char2 > 57343) { --this.endPos; return(this.HandleIllegalSurrogatePair(char1, char2, Token.LiteralContentString)); } ++this.endPos; } else { if (!XmlCharType.IsCharData(char1)) { --this.endPos; return(this.HandleIllegalCharacter(char1, Token.LiteralContentString)); } if ((int)char1 == 60) { goto label_15; } } }while (!this.isWhitespace || Scanner.IsXmlWhitespace(char1)); this.isWhitespace = false; } label_15: int length = this.endPos - num - 1; this.unescapedString = length > 0 ? this.Substring(this.startPos, length) : ""; if ((int)char1 == 60 || (int)char1 == 38) { --this.endPos; } return(Token.LiteralContentString); }
private Token ScanXmlProcessingInstructionsTag(bool stopAtEndOfLine) { int start = this.endPos; this.startPos = this.endPos; if ((int)this.GetChar(this.endPos - 1) == 63) { this.stillInsideMultiLineToken = true; this.ScanName(); return(Token.Identifier); } char char1; char char2; while (true) { char1 = this.GetChar(this.endPos); if ((int)char1 >= 55296 && (int)char1 <= 56319) { char2 = this.GetChar(this.endPos + 1); if ((int)char2 >= 56320 && (int)char2 <= 57343) { this.endPos += 2; } else { break; } } else if (XmlCharType.IsCharData(char1)) { while ((int)char1 == 63) { char1 = this.GetChar(++this.endPos); if ((int)char1 == 62) { if (this.endPos > start + 2) { --this.endPos; this.unescapedString = this.Substring(start, this.endPos - start); this.stillInsideMultiLineToken = true; return(Token.ProcessingInstructions); } ++this.endPos; this.state = Scanner.State.Xml; return(Token.EndOfTag); } if ((int)char1 == 0 && this.endPos >= this.maxPos) { if (stopAtEndOfLine) { this.stillInsideMultiLineToken = true; } return(Token.ProcessingInstructions); } } if ((int)char1 != 0 || this.endPos < this.maxPos) { ++this.endPos; } else { goto label_18; } } else { goto label_7; } } return(this.HandleIllegalSurrogatePair(char1, char2, Token.ProcessingInstructions)); label_7: return(this.HandleIllegalCharacter(char1, Token.ProcessingInstructions)); label_18: if (stopAtEndOfLine) { this.stillInsideMultiLineToken = true; } return(Token.ProcessingInstructions); }
static unsafe XmlCharType() { fixed(byte *properties = &XmlCharType.s_CharProperties[0]) { XmlCharType.SetProperties(new char[8] { '\t', '\n', '\r', '\r', ' ', '\xD7FF', '\xE000', '�' }, (byte)16, properties); XmlCharType.SetProperties(new char[30] { ':', ':', 'A', 'Z', '_', '_', 'a', 'z', 'À', 'Ö', 'Ø', 'ö', 'ø', '˿', 'Ͱ', 'ͽ', '\x037F', '\x1FFF', '\x200C', '\x200D', '\x2070', '\x218F', 'Ⰰ', '\x2FEF', '、', '\xD7FF', '豈', '\xFDCF', 'ﷰ', '�' }, (byte)28, properties); XmlCharType.SetProperties(new char[12] { '-', '-', '.', '.', '·', '·', '0', '9', '̀', 'ͯ', '‿', '⁀' }, (byte)24, properties); IntPtr num1 = (IntPtr)(properties + 9); int num2 = (int)(byte)((uint)*(byte *)num1 | 1U); *(sbyte *)num1 = (sbyte)num2; IntPtr num3 = (IntPtr)(properties + 10); int num4 = (int)(byte)((uint)*(byte *)num3 | 1U); *(sbyte *)num3 = (sbyte)num4; IntPtr num5 = (IntPtr)(properties + 13); int num6 = (int)(byte)((uint)*(byte *)num5 | 1U); *(sbyte *)num5 = (sbyte)num6; IntPtr num7 = (IntPtr)(properties + 32); int num8 = (int)(byte)((uint)*(byte *)num7 | 1U); *(sbyte *)num7 = (sbyte)num8; } }