private XmlToken TokenizeSimple(string text, XmlTokenKind kind, XmlTokenizerMode nextMode) { XmlToken token = new XmlToken(kind, text.Length); position += text.Length; mode = nextMode; return(token); }
private XmlToken TokenizeEntity() { Debug.Assert(mode == XmlTokenizerMode.OutsideElement); Debug.Assert(input[position] == '&'); XmlToken token = new XmlToken(XmlTokenKind.Entity, input.IndexOf(';', position) - position); position += token.Length; return(token); }
private XmlToken TokenizeAttributeValue() { Debug.Assert(mode == XmlTokenizerMode.AfterAttributeEquals); int closePosition = input.IndexOf(input[position], position + 1); XmlToken token = new XmlToken(XmlTokenKind.AttributeValue, closePosition + 1 - position); position = closePosition + 1; mode = XmlTokenizerMode.InsideElement; return(token); }
private XmlToken NextToken() { if (position >= input.Length) { return(new XmlToken(XmlTokenKind.EOF, 0)); } XmlToken token; switch (mode) { case XmlTokenizerMode.AfterAttributeEquals: token = TokenizeAttributeValue(); break; case XmlTokenizerMode.AfterAttributeName: token = TokenizeSimple("=", XmlTokenKind.Equals, XmlTokenizerMode.AfterAttributeEquals); break; case XmlTokenizerMode.AfterOpen: token = TokenizeName(XmlTokenKind.ElementName, XmlTokenizerMode.InsideElement); break; case XmlTokenizerMode.InsideCData: token = TokenizeInsideCData(); break; case XmlTokenizerMode.InsideComment: token = TokenizeInsideComment(); break; case XmlTokenizerMode.InsideElement: token = TokenizeInsideElement(); break; case XmlTokenizerMode.InsideProcessingInstruction: token = TokenizeInsideProcessingInstruction(); break; case XmlTokenizerMode.OutsideElement: token = TokenizeOutsideElement(); break; default: token = new XmlToken(XmlTokenKind.EOF, 0); Debug.Fail("missing case"); break; } return(token); }
private XmlToken TokenizeElementWhitespace() { int i; for (i = position; i < input.Length; i++) { if (!char.IsWhiteSpace(input[i])) { break; } } XmlToken token = new XmlToken(XmlTokenKind.ElementWhitespace, i - position); position = i; return(token); }
private XmlToken TokenizeInsideComment() { Debug.Assert(mode == XmlTokenizerMode.InsideComment); int tokenend = input.IndexOf("-->", position); if (position == tokenend) { position += "-->".Length; mode = XmlTokenizerMode.OutsideElement; return(new XmlToken(XmlTokenKind.CommentEnd, "-->".Length)); } else { XmlToken token = new XmlToken(XmlTokenKind.CommentText, tokenend - position); position = tokenend; return(token); } }
private XmlToken TokenizeInsideCData() { Debug.Assert(mode == XmlTokenizerMode.InsideCData); int tokenend = input.IndexOf("]]>", position); if (position == tokenend) { position += "]]>".Length; mode = XmlTokenizerMode.OutsideElement; return(new XmlToken(XmlTokenKind.CDataEnd, "]]>".Length)); } else { XmlToken token = new XmlToken(XmlTokenKind.TextContent, tokenend - position); position = tokenend; return(token); } }
private XmlToken TokenizeInsideProcessingInstruction() { Debug.Assert(mode == XmlTokenizerMode.InsideProcessingInstruction); int tokenend = input.IndexOf("?>", position); if (position == tokenend) { position += "?>".Length; mode = XmlTokenizerMode.OutsideElement; return(new XmlToken(XmlTokenKind.CloseProcessingInstruction, "?>".Length)); } else { XmlToken token = new XmlToken(XmlTokenKind.TextContent, tokenend - position); position = tokenend; return(token); } }
private XmlToken TokenizeName(XmlTokenKind kind, XmlTokenizerMode nextMode) { Debug.Assert(mode == XmlTokenizerMode.AfterOpen || mode == XmlTokenizerMode.InsideElement); int i; for (i = position; i < input.Length; i++) { if (!IsNameCharacter(input[i])) { break; } } XmlToken token = new XmlToken(kind, i - position); mode = nextMode; position = i; return(token); }
//// We break on newlines because that makes it easier for us //// to ignore the space after comments //private Token TokenizeWhitespaceContent() //{ // Debug.Assert(char.IsWhiteSpace(input[position])); // bool sawNewline = false; // int i; // for (i = position; i < input.Length; i++) { // if (!char.IsWhiteSpace(input[i])) { // break; // } else if (input[i] == '\n' || input[i] == '\r') { // sawNewline = true; // } else if (sawNewline) { // break; // } // } // Token token = new Token(TokenKind.WhitespaceContent, i - position); // position = i; // return token; //} private XmlToken TokenizeText() { Debug.Assert(input[position] != '<'); Debug.Assert(input[position] != '&'); Debug.Assert(mode == XmlTokenizerMode.OutsideElement); int i; for (i = position; i < input.Length; i++) { if (input[i] == '<' || input[i] == '&') { break; } } XmlToken token = new XmlToken(XmlTokenKind.TextContent, i - position); position = i; return(token); }