本文整理汇总了C#中HtmlTokenType类的典型用法代码示例。如果您正苦于以下问题:C# HtmlTokenType类的具体用法?C# HtmlTokenType怎么用?C# HtmlTokenType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HtmlTokenType类属于命名空间,在下文中一共展示了HtmlTokenType类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HtmlLexicalAnalyzer
/// <summary>
/// initializes the _inputStringReader member with the string to be read
/// also sets initial values for _nextCharacterCode and _nextTokenType
/// </summary>
/// <param name="inputTextString">
/// text string to be parsed for xml content
/// </param>
internal HtmlLexicalAnalyzer(string inputTextString)
{
_inputStringReader = new StringReader(inputTextString);
_nextCharacterCode = 0;
_nextCharacter = ' ';
_lookAheadCharacterCode = _inputStringReader.Read();
_lookAheadCharacter = (char)_lookAheadCharacterCode;
_previousCharacter = ' ';
_ignoreNextWhitespace = true;
_nextToken = new StringBuilder(100);
_nextTokenType = HtmlTokenType.Text;
// read the first character so we have some value for the NextCharacter property
this.GetNextCharacter();
}
示例2: GetNextEqualSignToken
/// <summary>
/// Unconditionally returns equal sign token. Even if there is no
/// real equal sign in the stream, it behaves as if it were there.
/// Does not guarantee token reader advancing.
/// </summary>
internal void GetNextEqualSignToken()
{
Debug.Assert(_nextTokenType != HtmlTokenType.EOF);
_nextToken.Length = 0;
_nextToken.Append('=');
_nextTokenType = HtmlTokenType.EqualSign;
this.SkipWhiteSpace();
if (this.NextCharacter == '=')
{
// '=' is not in the list of entities, so no need to check for entities here
this.GetNextCharacter();
}
}
示例3: GetNextContentToken
/// <summary>
/// retrieves next recognizable token from input string
/// and identifies its type
/// if no valid token is found, the output parameters are set to null
/// if end of stream is reached without matching any token, token type
/// paramter is set to EOF
/// </summary>
internal void GetNextContentToken()
{
Debug.Assert(_nextTokenType != HtmlTokenType.EOF);
_nextToken.Length = 0;
if (this.IsAtEndOfStream)
{
_nextTokenType = HtmlTokenType.EOF;
return;
}
if (this.IsAtTagStart)
{
this.GetNextCharacter();
if (this.NextCharacter == '/')
{
_nextToken.Append("</");
_nextTokenType = HtmlTokenType.ClosingTagStart;
// advance
this.GetNextCharacter();
_ignoreNextWhitespace = false; // Whitespaces after closing tags are significant
}
else
{
_nextTokenType = HtmlTokenType.OpeningTagStart;
_nextToken.Append("<");
_ignoreNextWhitespace = true; // Whitespaces after opening tags are insignificant
}
}
else if (this.IsAtDirectiveStart)
{
// either a comment or CDATA
this.GetNextCharacter();
if (_lookAheadCharacter == '[')
{
// cdata
this.ReadDynamicContent();
}
else if (_lookAheadCharacter == '-')
{
this.ReadComment();
}
else
{
// neither a comment nor cdata, should be something like DOCTYPE
// skip till the next tag ender
this.ReadUnknownDirective();
}
}
else
{
// read text content, unless you encounter a tag
_nextTokenType = HtmlTokenType.Text;
while (!this.IsAtTagStart && !this.IsAtEndOfStream && !this.IsAtDirectiveStart)
{
if (this.NextCharacter == '<' && !this.IsNextCharacterEntity && _lookAheadCharacter == '?')
{
// ignore processing directive
this.SkipProcessingDirective();
}
else
{
if (this.NextCharacter <= ' ')
{
// Respect xml:preserve or its equivalents for whitespace processing
if (_ignoreNextWhitespace)
{
// Ignore repeated whitespaces
}
else
{
// Treat any control character sequence as one whitespace
_nextToken.Append(' ');
}
_ignoreNextWhitespace = true; // and keep ignoring the following whitespaces
}
else
{
_nextToken.Append(this.NextCharacter);
_ignoreNextWhitespace = false;
}
this.GetNextCharacter();
}
}
}
}
示例4: GetNextAtomToken
/// <summary>
/// Unconditionally returns an atomic value for an attribute
/// Even if there is no appropriate token it returns Atom value
/// Does not guarantee token reader advancing.
/// </summary>
internal void GetNextAtomToken()
{
Debug.Assert(_nextTokenType != HtmlTokenType.EOF);
_nextToken.Length = 0;
this.SkipWhiteSpace();
_nextTokenType = HtmlTokenType.Atom;
if ((this.NextCharacter == '\'' || this.NextCharacter == '"') && !this.IsNextCharacterEntity)
{
char startingQuote = this.NextCharacter;
this.GetNextCharacter();
// Consume all characters between quotes
while (!(this.NextCharacter == startingQuote && !this.IsNextCharacterEntity) && !this.IsAtEndOfStream)
{
_nextToken.Append(this.NextCharacter);
this.GetNextCharacter();
}
if (this.NextCharacter == startingQuote)
{
this.GetNextCharacter();
}
// complete the quoted value
// IE keeps reading until it finds a closing quote or end of file
// if end of file, it treats current value as text
// if it finds a closing quote at any point within the text, it eats everything between the quotes
// however, we could stop when we encounter end of file or an angle bracket of any kind
// and assume there was a quote there
// so the attribute value may be meaningless but it is never treated as text
}
else
{
while (!this.IsAtEndOfStream && !Char.IsWhiteSpace(this.NextCharacter) && this.NextCharacter != '>')
{
_nextToken.Append(this.NextCharacter);
this.GetNextCharacter();
}
}
}
示例5: TokenTypeAsString
string TokenTypeAsString(HtmlTokenType t) {
string type = t.ToString();
//int lastDot = type.LastIndexOf('.');
return type;
}
示例6: HtmlToken
public HtmlToken(HtmlTokenType type, TextPosition position, String name)
{
_type = type;
_position = position;
_name = name;
}
示例7: FromBounds
public static HtmlToken FromBounds(HtmlTokenType type, int start, int end, bool wellFormed) {
return new HtmlToken(type, start, end - start, wellFormed);
}
示例8: ReadDynamicContent
/// <summary>
/// skips dynamic content starting with '<![' and ending with ']>'
/// </summary>
private void ReadDynamicContent()
{
// verify that we are at dynamic content, which may include CDATA
Debug.Assert(_previousCharacter == '<' && _nextCharacter == '!' && _lookAheadCharacter == '[');
// Let's treat this as empty text
_nextTokenType = HtmlTokenType.Text;
_nextToken.Length = 0;
// advance twice, once to get the lookahead character and then to reach the start of the cdata
this.GetNextCharacter();
this.GetNextCharacter();
// some directives may start with a <![ and then have some data and they will just end with a ]>
// this function is modified to stop at the sequence ]> and not ]]>
// this means that CDATA and anything else expressed in their own set of [] within the <! [...]>
// directive cannot contain a ]> sequence. However it is doubtful that cdata could contain such
// sequence anyway, it probably stops at the first ]
while (!(_nextCharacter == ']' && _lookAheadCharacter == '>') && !this.IsAtEndOfStream)
{
// advance
this.GetNextCharacter();
}
if (!this.IsAtEndOfStream)
{
// advance, first to the last >
this.GetNextCharacter();
// then advance past it to the next character after processing directive
this.GetNextCharacter();
}
}
示例9: HtmlToken
public HtmlToken(HtmlTokenType type, int start, int length)
: this(type, start, length, true) {
}
示例10: HtmlTagToken
/// <summary>
/// Creates a new HTML TagToken with the defined name.
/// </summary>
/// <param name="type">The type of the tag token.</param>
/// <param name="position">The token's position.</param>
/// <param name="name">The name of the tag.</param>
public HtmlTagToken(HtmlTokenType type, TextPosition position, String name)
: base(type, position, name)
{
_attributes = new List<KeyValuePair<String, String>>();
}
示例11: GetNextTagToken
/// <summary>
/// Unconditionally returns a token which is one of: TagEnd, EmptyTagEnd, Name, Atom or EndOfStream
/// Does not guarantee token reader advancing.
/// </summary>
internal void GetNextTagToken()
{
_nextToken.Length = 0;
if (this.IsAtEndOfStream)
{
_nextTokenType = HtmlTokenType.EOF;
return;
}
this.SkipWhiteSpace();
if (this.NextCharacter == '>' && !this.IsNextCharacterEntity)
{
// > should not end a tag, so make sure it's not an entity
_nextTokenType = HtmlTokenType.TagEnd;
_nextToken.Append('>');
this.GetNextCharacter();
}
else if (this.NextCharacter == '/' && _lookAheadCharacter == '>')
{
// could be start of closing of empty tag
_nextTokenType = HtmlTokenType.EmptyTagEnd;
_nextToken.Append("/>");
this.GetNextCharacter();
this.GetNextCharacter();
_ignoreNextWhitespace = false; // Whitespace after no-scope tags are sifnificant
}
else if (IsGoodForNameStart(this.NextCharacter))
{
_nextTokenType = HtmlTokenType.Name;
// starts a name
// we allow character entities here
// we do not throw exceptions here if end of stream is encountered
// just stop and return whatever is in the token
// if the parser is not expecting end of file after this it will call
// the get next token function and throw an exception
while (IsGoodForName(this.NextCharacter) && !this.IsAtEndOfStream)
{
_nextToken.Append(this.NextCharacter);
this.GetNextCharacter();
}
}
else
{
// Unexpected type of token for a tag. Reprot one character as Atom, expecting that HtmlParser will ignore it.
_nextTokenType = HtmlTokenType.Atom;
_nextToken.Append(this.NextCharacter);
this.GetNextCharacter();
}
}
示例12: ReadComment
/// <summary>
/// skips comments starting with '<!-' and ending with '-->'
/// NOTE: 10/06/2004: processing changed, will now skip anything starting with
/// the "<!-" sequence and ending in "!>" or "->", because in practice many html pages do not
/// use the full comment specifying conventions
/// </summary>
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();
}
}
示例13: ReadUnknownDirective
/// <summary>
/// skips past unknown directives that start with "<!" but are not comments or Cdata
/// ignores content of such directives until the next ">" character
/// applies to directives such as DOCTYPE, etc that we do not presently support
/// </summary>
private void ReadUnknownDirective()
{
// verify that we are at an unknown directive
Debug.Assert(_previousCharacter == '<' && _nextCharacter == '!' && !(_lookAheadCharacter == '-' || _lookAheadCharacter == '['));
// Let's treat this as empty text
_nextTokenType = HtmlTokenType.Text;
_nextToken.Length = 0;
// advance to the next character
this.GetNextCharacter();
// skip to the first tag end we find
while (!(_nextCharacter == '>' && !IsNextCharacterEntity) && !this.IsAtEndOfStream)
{
this.GetNextCharacter();
}
if (!this.IsAtEndOfStream)
{
// advance past the tag end
this.GetNextCharacter();
}
}
示例14: ComplexAttributeValueToken
public ComplexAttributeValueToken(IHtmlToken token, char openQuote, char closeQuote)
: base(token) {
_tokenType = token.TokenType;
_openQuote = openQuote;
_closeQuote = closeQuote;
}