Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        /// <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);
                }
            }
        }
Exemplo n.º 3
0
        /// <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;
        }
Exemplo n.º 4
0
 /// <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;
 }
Exemplo n.º 5
0
		/// <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;
		}
Exemplo n.º 6
0
		/// <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;
		}
Exemplo n.º 7
0
 public void ChangeKind(HtmlTokenKind kind)
 {
     Kind = kind;
 }
Exemplo n.º 8
0
 public void Set(HtmlTokenKind kind, TextRange range, bool isComplete)
 {
     Set(range, isComplete);
     Kind = kind;
 }
Exemplo n.º 9
0
 private HtmlToken(HtmlTokenKind kind, TextRange range, bool isComplete) : base(range, isComplete)
 {
     Kind = kind;
 }