summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/machine.rs68
-rw-r--r--src/tokenizer.rs25
2 files changed, 59 insertions, 34 deletions
diff --git a/src/machine.rs b/src/machine.rs
index aa07900..e6f439b 100644
--- a/src/machine.rs
+++ b/src/machine.rs
@@ -124,7 +124,7 @@ pub fn consume<R: Reader, E: Emitter<R>>(
Ok(ControlToken::Continue)
}
Some(x) if x.is_ascii_alphabetic() => {
- slf.emitter.init_start_tag(&slf.reader);
+ slf.init_start_tag();
slf.state = State::TagName;
slf.unread_char(Some(x));
Ok(ControlToken::Continue)
@@ -151,7 +151,7 @@ pub fn consume<R: Reader, E: Emitter<R>>(
},
State::EndTagOpen => match slf.read_char()? {
Some(x) if x.is_ascii_alphabetic() => {
- slf.emitter.init_end_tag(&slf.reader);
+ slf.init_end_tag();
slf.state = State::TagName;
slf.unread_char(Some(x));
Ok(ControlToken::Continue)
@@ -185,16 +185,16 @@ pub fn consume<R: Reader, E: Emitter<R>>(
}
Some('>') => {
slf.state = State::Data;
- slf.emitter.emit_current_tag();
+ slf.emit_current_tag();
Ok(ControlToken::Continue)
}
Some('\0') => {
slf.emit_error(Error::UnexpectedNullCharacter);
- slf.emitter.push_tag_name("\u{fffd}");
+ slf.push_tag_name("\u{fffd}");
Ok(ControlToken::Continue)
}
Some(x) => {
- slf.emitter.push_tag_name(ctostr!(x.to_ascii_lowercase()));
+ slf.push_tag_name(ctostr!(x.to_ascii_lowercase()));
Ok(ControlToken::Continue)
}
None => {
@@ -217,7 +217,7 @@ pub fn consume<R: Reader, E: Emitter<R>>(
},
State::RcDataEndTagOpen => match slf.read_char()? {
Some(x) if x.is_ascii_alphabetic() => {
- slf.emitter.init_end_tag(&slf.reader);
+ slf.init_end_tag();
slf.state = State::RcDataEndTagName;
slf.unread_char(Some(x));
Ok(ControlToken::Continue)
@@ -230,21 +230,21 @@ pub fn consume<R: Reader, E: Emitter<R>>(
}
},
State::RcDataEndTagName => match slf.read_char()? {
- Some(whitespace_pat!()) if slf.emitter.current_is_appropriate_end_tag_token() => {
+ Some(whitespace_pat!()) if slf.current_end_tag_is_appropriate() => {
slf.state = State::BeforeAttributeName;
Ok(ControlToken::Continue)
}
- Some('/') if slf.emitter.current_is_appropriate_end_tag_token() => {
+ Some('/') if slf.current_end_tag_is_appropriate() => {
slf.state = State::SelfClosingStartTag;
Ok(ControlToken::Continue)
}
- Some('>') if slf.emitter.current_is_appropriate_end_tag_token() => {
+ Some('>') if slf.current_end_tag_is_appropriate() => {
slf.state = State::Data;
- slf.emitter.emit_current_tag();
+ slf.emit_current_tag();
Ok(ControlToken::Continue)
}
Some(x) if x.is_ascii_alphabetic() => {
- slf.emitter.push_tag_name(ctostr!(x.to_ascii_lowercase()));
+ slf.push_tag_name(ctostr!(x.to_ascii_lowercase()));
slf.temporary_buffer.push(x);
Ok(ControlToken::Continue)
}
@@ -272,7 +272,7 @@ pub fn consume<R: Reader, E: Emitter<R>>(
},
State::RawTextEndTagOpen => match slf.read_char()? {
Some(x) if x.is_ascii_alphabetic() => {
- slf.emitter.init_end_tag(&slf.reader);
+ slf.init_end_tag();
slf.state = State::RawTextEndTagName;
slf.unread_char(Some(x));
Ok(ControlToken::Continue)
@@ -285,21 +285,21 @@ pub fn consume<R: Reader, E: Emitter<R>>(
}
},
State::RawTextEndTagName => match slf.read_char()? {
- Some(whitespace_pat!()) if slf.emitter.current_is_appropriate_end_tag_token() => {
+ Some(whitespace_pat!()) if slf.current_end_tag_is_appropriate() => {
slf.state = State::BeforeAttributeName;
Ok(ControlToken::Continue)
}
- Some('/') if slf.emitter.current_is_appropriate_end_tag_token() => {
+ Some('/') if slf.current_end_tag_is_appropriate() => {
slf.state = State::SelfClosingStartTag;
Ok(ControlToken::Continue)
}
- Some('>') if slf.emitter.current_is_appropriate_end_tag_token() => {
+ Some('>') if slf.current_end_tag_is_appropriate() => {
slf.state = State::Data;
- slf.emitter.emit_current_tag();
+ slf.emit_current_tag();
Ok(ControlToken::Continue)
}
Some(x) if x.is_ascii_alphabetic() => {
- slf.emitter.push_tag_name(ctostr!(x.to_ascii_lowercase()));
+ slf.push_tag_name(ctostr!(x.to_ascii_lowercase()));
slf.temporary_buffer.push(x);
Ok(ControlToken::Continue)
}
@@ -332,7 +332,7 @@ pub fn consume<R: Reader, E: Emitter<R>>(
},
State::ScriptDataEndTagOpen => match slf.read_char()? {
Some(x) if x.is_ascii_alphabetic() => {
- slf.emitter.init_end_tag(&slf.reader);
+ slf.init_end_tag();
slf.state = State::ScriptDataEndTagName;
slf.unread_char(Some(x));
Ok(ControlToken::Continue)
@@ -345,21 +345,21 @@ pub fn consume<R: Reader, E: Emitter<R>>(
}
},
State::ScriptDataEndTagName => match slf.read_char()? {
- Some(whitespace_pat!()) if slf.emitter.current_is_appropriate_end_tag_token() => {
+ Some(whitespace_pat!()) if slf.current_end_tag_is_appropriate() => {
slf.state = State::BeforeAttributeName;
Ok(ControlToken::Continue)
}
- Some('/') if slf.emitter.current_is_appropriate_end_tag_token() => {
+ Some('/') if slf.current_end_tag_is_appropriate() => {
slf.state = State::SelfClosingStartTag;
Ok(ControlToken::Continue)
}
- Some('>') if slf.emitter.current_is_appropriate_end_tag_token() => {
+ Some('>') if slf.current_end_tag_is_appropriate() => {
slf.state = State::Data;
- slf.emitter.emit_current_tag();
+ slf.emit_current_tag();
Ok(ControlToken::Continue)
}
Some(x) if x.is_ascii_alphabetic() => {
- slf.emitter.push_tag_name(ctostr!(x.to_ascii_lowercase()));
+ slf.push_tag_name(ctostr!(x.to_ascii_lowercase()));
slf.temporary_buffer.push(x.to_ascii_lowercase());
Ok(ControlToken::Continue)
}
@@ -497,7 +497,7 @@ pub fn consume<R: Reader, E: Emitter<R>>(
},
State::ScriptDataEscapedEndTagOpen => match slf.read_char()? {
Some(x) if x.is_ascii_alphabetic() => {
- slf.emitter.init_end_tag(&slf.reader);
+ slf.init_end_tag();
slf.state = State::ScriptDataEscapedEndTagName;
slf.unread_char(Some(x));
Ok(ControlToken::Continue)
@@ -510,21 +510,21 @@ pub fn consume<R: Reader, E: Emitter<R>>(
}
},
State::ScriptDataEscapedEndTagName => match slf.read_char()? {
- Some(whitespace_pat!()) if slf.emitter.current_is_appropriate_end_tag_token() => {
+ Some(whitespace_pat!()) if slf.current_end_tag_is_appropriate() => {
slf.state = State::BeforeAttributeName;
Ok(ControlToken::Continue)
}
- Some('/') if slf.emitter.current_is_appropriate_end_tag_token() => {
+ Some('/') if slf.current_end_tag_is_appropriate() => {
slf.state = State::SelfClosingStartTag;
Ok(ControlToken::Continue)
}
- Some('>') if slf.emitter.current_is_appropriate_end_tag_token() => {
+ Some('>') if slf.current_end_tag_is_appropriate() => {
slf.state = State::Data;
- slf.emitter.emit_current_tag();
+ slf.emit_current_tag();
Ok(ControlToken::Continue)
}
Some(x) if x.is_ascii_alphabetic() => {
- slf.emitter.push_tag_name(ctostr!(x.to_ascii_lowercase()));
+ slf.push_tag_name(ctostr!(x.to_ascii_lowercase()));
slf.temporary_buffer.push(x);
Ok(ControlToken::Continue)
}
@@ -735,7 +735,7 @@ pub fn consume<R: Reader, E: Emitter<R>>(
}
Some('>') => {
slf.state = State::Data;
- slf.emitter.emit_current_tag();
+ slf.emit_current_tag();
Ok(ControlToken::Continue)
}
None => {
@@ -764,7 +764,7 @@ pub fn consume<R: Reader, E: Emitter<R>>(
Some('>') => {
slf.emit_error(Error::MissingAttributeValue);
slf.state = State::Data;
- slf.emitter.emit_current_tag();
+ slf.emit_current_tag();
Ok(ControlToken::Continue)
}
c => {
@@ -834,7 +834,7 @@ pub fn consume<R: Reader, E: Emitter<R>>(
}
Some('>') => {
slf.state = State::Data;
- slf.emitter.emit_current_tag();
+ slf.emit_current_tag();
Ok(ControlToken::Continue)
}
Some('\0') => {
@@ -867,7 +867,7 @@ pub fn consume<R: Reader, E: Emitter<R>>(
}
Some('>') => {
slf.state = State::Data;
- slf.emitter.emit_current_tag();
+ slf.emit_current_tag();
Ok(ControlToken::Continue)
}
None => {
@@ -885,7 +885,7 @@ pub fn consume<R: Reader, E: Emitter<R>>(
Some('>') => {
slf.emitter.set_self_closing(&slf.reader);
slf.state = State::Data;
- slf.emitter.emit_current_tag();
+ slf.emit_current_tag();
Ok(ControlToken::Continue)
}
None => {
diff --git a/src/tokenizer.rs b/src/tokenizer.rs
index 62cc6a4..78d4fc4 100644
--- a/src/tokenizer.rs
+++ b/src/tokenizer.rs
@@ -116,6 +116,31 @@ impl<R: Reader, E: Emitter<R>> Tokenizer<R, E> {
}
#[inline]
+ pub(crate) fn current_end_tag_is_appropriate(&mut self) -> bool {
+ self.emitter.current_is_appropriate_end_tag_token()
+ }
+
+ #[inline]
+ pub(crate) fn init_start_tag(&mut self) {
+ self.emitter.init_start_tag(&self.reader);
+ }
+
+ #[inline]
+ pub(crate) fn init_end_tag(&mut self) {
+ self.emitter.init_end_tag(&self.reader);
+ }
+
+ #[inline]
+ pub(crate) fn push_tag_name(&mut self, s: &str) {
+ self.emitter.push_tag_name(s);
+ }
+
+ #[inline]
+ pub(crate) fn emit_current_tag(&mut self) {
+ self.emitter.emit_current_tag();
+ }
+
+ #[inline]
pub(crate) fn unread_char(&mut self, c: Option<char>) {
self.to_reconsume.push(c);
}