Skip to main content

Tokenizer

Struct Tokenizer 

Source
pub struct Tokenizer<'a> {
Show 24 fields input: &'a str, bytes: &'a [u8], pos: usize, state: State, allow_cdata: bool, last_start_tag: String, char_buf: String, pending_token: Option<Token>, cur_tag_is_end: bool, cur_tag_name: String, cur_tag_attrs: Vec<(String, String)>, cur_tag_self_closing: bool, has_cur_attr: bool, cur_attr_name: String, cur_attr_val: String, cur_comment: String, cur_doctype_name: Option<String>, cur_doctype_public: Option<String>, cur_doctype_system: Option<String>, cur_doctype_force_quirks: bool, temporary_buffer: String, cur_pi_target: String, cur_pi_data: String, cur_pi_quote: Option<u8>,
}
Expand description

WHATWG HTML §13.2.5 トークナイザ本体。

Fields§

§input: &'a str§bytes: &'a [u8]§pos: usize§state: State§allow_cdata: bool§last_start_tag: String§char_buf: String§pending_token: Option<Token>§cur_tag_is_end: bool§cur_tag_name: String§cur_tag_attrs: Vec<(String, String)>§cur_tag_self_closing: bool§has_cur_attr: bool§cur_attr_name: String§cur_attr_val: String§cur_comment: String§cur_doctype_name: Option<String>§cur_doctype_public: Option<String>§cur_doctype_system: Option<String>§cur_doctype_force_quirks: bool§temporary_buffer: String§cur_pi_target: String§cur_pi_data: String§cur_pi_quote: Option<u8>

Implementations§

Source§

impl<'a> Tokenizer<'a>

Source

pub fn new(input: &'a str) -> Self

デフォルト状態(Data)で新しいトークナイザを作成する。

Source

pub fn with_initial_state( input: &'a str, state: State, last_start_tag: Option<&str>, ) -> Self

初期状態と直前の開始タグ名(last_start_tag)を指定してトークナイザを作成する。

Source

pub fn set_state(&mut self, state: State)

ツリービルダからの状態遷移指示(script→ScriptData 等)を反映する。

Source

pub fn set_allow_cdata(&mut self, allow: bool)

外国語要素(SVG / MathML)内かどうかを設定し、<![CDATA[...]]> の許可を切り替える。

Source

pub fn position(&self) -> usize

現在のバイト読み取り位置を返す。

Source

pub fn tokenize_all(input: &'a str) -> Vec<Token>

入力末尾までの全トークン(Eof を除く)をベクタに収集して返す。

Source

pub fn tokenize_all_with( input: &'a str, state: State, last_start_tag: Option<&str>, ) -> Vec<Token>

初期状態・直前開始タグ名を指定して全トークン(Eof を除く)を収集する。

Source

pub fn collect_all(&mut self) -> Vec<Token>

現在の状態から Eof までの全トークン(Eof を除く)を収集する。

Source

fn peek_byte_norm(&self) -> Option<u8>

改行正規化(\r\n / \r → \n)を行いながら現在位置のバイトを先読みする。

Source

fn advance_norm(&mut self)

改行正規化に従って現在位置を 1 文字(ASCII は 1 バイト、\r\n は 2 バイト)進める。

Source

fn consume_any_char(&mut self) -> Option<char>

非 ASCII UTF-8 文字を含む「その他(Anything else)」の 1 文字を読み取り、pos を進める。

Source

fn starts_with_ignore_ascii_case(&self, ascii_pat: &[u8]) -> bool

文字列の先頭が ascii_pat と ASCII 大文字小文字無視で一致するか検査する(パターンの長さは短い ASCII のみ)。

Source

fn starts_with_exact(&self, pat: &[u8]) -> bool

文字列の先頭が pat と完全一致するか検査する。

Source

fn emit_non_char_token(&mut self, tok: Token) -> Token

溜まった文字があれば先に Character トークンを返し、tok を次回返却用に保留する。

Source

fn start_new_tag(&mut self, is_end: bool)

新しい開始タグまたは終了タグの構築を始める。

Source

fn start_new_attr(&mut self)

新しい属性の構築を始める(直前に構築中の属性があれば先に確定する)。

Source

fn finish_current_attr(&mut self)

現在の属性をタグの属性一覧に確定する。重複属性は仕様どおり最初の 1 つだけを保持する。

Source

fn emit_current_tag(&mut self) -> Token

現在のタグをトークン化して発行する(終了タグの属性・self-closing フラグは出力しない)。

Source

fn emit_current_comment(&mut self) -> Token

現在のコメントを発行する。

Source

fn emit_current_pi(&mut self) -> Token

現在の処理命令を発行する。

Source

fn emit_eof_in_pi(&mut self) -> Token

処理命令の途中で入力が終わった(eof-in-processing-instruction)。作りかけは捨て、溜まった文字と Eof だけを返す。

Source

fn pi_to_bogus_comment(&mut self)

処理命令になれない入力(対象名に使えない文字・xml で始まる対象名)を、?+読んだ対象名を中身とする 怪しいコメント(bogus comment)に切り替える。今の文字は BogusComment で読み直す。

Source

fn start_new_doctype(&mut self, force_quirks: bool)

新しい DOCTYPE トークン構築を始める。

Source

fn emit_current_doctype(&mut self) -> Token

現在の DOCTYPE トークンを発行する。

Source

fn is_appropriate_end_tag(&self) -> bool

現在の終了タグが直前の開始タグと一致する(appropriate end tag)か判定する。

Source

fn consume_char_ref_into_char_buf(&mut self, in_attr: bool)

文字参照(&...)を & の位置から復号し、指定バッファへ書き込む。

Source

fn consume_char_ref_into_attr_val(&mut self)

属性値の中の文字参照(&...)を復号し、cur_attr_val へ書き込む。

Source

fn step_special_end_tag_name(&mut self, ret: EndTagReturn) -> Option<Token>

RCDATA / RAWTEXT / ScriptData / ScriptDataEscaped の終了タグ名状態を共通処理する。

Source

fn step_double_escape(&mut self, target_if_script: State, target_else: State)

ScriptDataDoubleEscapeStart と ScriptDataDoubleEscapeEnd の共通ステップ。

Source

pub fn next_token(&mut self) -> Token

次のトークンを 1 つ返す。入力末尾に達したら Token::Eof を返す。

Source

fn step_doctype_quoted( &mut self, is_public: bool, quote: u8, after_state: State, ) -> Option<Token>

DOCTYPE 識別子(引用符付き)の共通ステップ。

Source

fn emit_eof_after_comment(&mut self) -> Token

EOF 到達時に溜まっていた文字→コメント(または DOCTYPE)→Eof の順で返すヘルパー。

Source

fn emit_eof_after_doctype(&mut self) -> Token

Auto Trait Implementations§

§

impl<'a> Freeze for Tokenizer<'a>

§

impl<'a> RefUnwindSafe for Tokenizer<'a>

§

impl<'a> Send for Tokenizer<'a>

§

impl<'a> Sync for Tokenizer<'a>

§

impl<'a> Unpin for Tokenizer<'a>

§

impl<'a> UnsafeUnpin for Tokenizer<'a>

§

impl<'a> UnwindSafe for Tokenizer<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.