private void ReadComment()
{
// verify that we are at a comment
Debug.Assert(_previousCharacter == '<' && _nextCharacter == '!' && _lookAheadCharacter == '-');
// Initialize a token
_nextTokenType = HtmlTokenType.Comment;
_nextToken.Length = 0;
// advance to the next character, so that to be at the start of comment value
this.GetNextCharacter(); // get first '-'
this.GetNextCharacter(); // get second '-'
this.GetNextCharacter(); // get first character of comment content
while (true)
{
// Read text until end of comment
// Note that in many actual html pages comments end with "!>" (while xml standard is "-->")
while (!this.IsAtEndOfStream && !(_nextCharacter == '-' && _lookAheadCharacter == '-' || _nextCharacter == '!' && _lookAheadCharacter == '>'))
{
_nextToken.Append(this.NextCharacter);
this.GetNextCharacter();
}
// Finish comment reading
this.GetNextCharacter();
if (_previousCharacter == '-' && _nextCharacter == '-' && _lookAheadCharacter == '>')
{
// Standard comment end. Eat it and exit the loop
this.GetNextCharacter(); // get '>'
break;
}
else if (_previousCharacter == '!' && _nextCharacter == '>')
{
// Nonstandard but possible comment end - '!>'. Exit the loop
break;
}
else
{
// Not an end. Save character and continue continue reading
_nextToken.Append(_previousCharacter);
continue;
}
}
// Read end of comment combination
if (_nextCharacter == '>')
{
this.GetNextCharacter();
}
}