public static HtmlToken Make(HtmlTokenKind kind, TextRange range, bool isComplete) { if (_pool == null) { _pool = new ObjectPool <HtmlToken>(() => new HtmlToken()); } HtmlToken result = _pool.Aquire(); result.Set(kind, range, isComplete); return(result); }
/// <summary> /// Read one token from the stream. /// </summary> /// <returns>True if a token was read, False if end of stream is reached.</returns> public bool Read() { textBuffer = null; tagToken = null; stateMachine.ResetEmit(); while (true) { stateMachine.State(); if (stateMachine.EmitTagToken != null) { TokenKind = stateMachine.EmitTagToken.EndTag ? HtmlTokenKind.EndTag : HtmlTokenKind.Tag; stateMachine.SetNextStateFromTagName(); if (stateMachine.EmitTagToken.EndTag == false) { stateMachine.RememberLastStartTagName(); } tagToken = stateMachine.EmitTagToken; return(true); } if (stateMachine.EmitDataBuffer != null) { TokenKind = HtmlTokenKind.Text; textBuffer = stateMachine.EmitDataBuffer; return(true); } if (stateMachine.EmitCommentBuffer != null) { TokenKind = HtmlTokenKind.Comment; textBuffer = stateMachine.EmitCommentBuffer; return(true); } if (stateMachine.EmitDoctypeToken != null) { TokenKind = HtmlTokenKind.Doctype; tagToken = stateMachine.EmitDoctypeToken; return(true); } if (stateMachine.Eof) { return(false); } } }
/// <summary> /// Initializes a new instance of the <see cref="HtmlDataToken"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="HtmlDataToken"/>. /// </remarks> /// <param name="kind">The kind of character data.</param> /// <param name="data">The character data.</param> /// <exception cref="System.ArgumentOutOfRangeException"> /// <paramref name="kind"/> is not a valid <see cref="HtmlTokenKind"/>. /// </exception> /// <exception cref="System.ArgumentNullException"> /// <paramref name="data"/> is <c>null</c>. /// </exception> protected HtmlDataToken(HtmlTokenKind kind, string data) : base(kind) { switch (kind) { default: throw new ArgumentOutOfRangeException(nameof(kind)); case HtmlTokenKind.ScriptData: case HtmlTokenKind.CData: case HtmlTokenKind.Data: break; } if (data == null) { throw new ArgumentNullException(nameof(data)); } Data = data; }
/// <summary> /// Initializes a new instance of the <see cref="HtmlToken"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="HtmlToken"/>. /// </remarks> /// <param name="kind">The kind of token.</param> protected HtmlToken(HtmlTokenKind kind) { Kind = kind; }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.Text.HtmlToken"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="HtmlToken"/>. /// </remarks> /// <param name="kind">The kind of token.</param> protected HtmlToken (HtmlTokenKind kind) { Kind = kind; }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.Text.HtmlDataToken"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="HtmlDataToken"/>. /// </remarks> /// <param name="kind">The kind of character data.</param> /// <param name="data">The character data.</param> /// <exception cref="System.ArgumentOutOfRangeException"> /// <paramref name="kind"/> is not a valid <see cref="HtmlTokenKind"/>. /// </exception> /// <exception cref="System.ArgumentNullException"> /// <paramref name="data"/> is <c>null</c>. /// </exception> protected HtmlDataToken (HtmlTokenKind kind, string data) : base (kind) { switch (kind) { default: throw new ArgumentOutOfRangeException (nameof (kind)); case HtmlTokenKind.ScriptData: case HtmlTokenKind.CData: case HtmlTokenKind.Data: break; } if (data == null) throw new ArgumentNullException (nameof (data)); Data = data; }
public void ChangeKind(HtmlTokenKind kind) { Kind = kind; }
public void Set(HtmlTokenKind kind, TextRange range, bool isComplete) { Set(range, isComplete); Kind = kind; }
private HtmlToken(HtmlTokenKind kind, TextRange range, bool isComplete) : base(range, isComplete) { Kind = kind; }