aboutsummaryrefslogtreecommitdiff
path: root/src/tokenizer/char_ref/mod.rs
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-11-30 07:28:21 +0100
committerMartin Fischer <martin@push-f.com>2021-11-30 11:22:35 +0100
commit14f1a85d994ad97dae3d9de735fc51adb25d390a (patch)
tree0fa0d7c173a19dcb7117132325a801808302bcf8 /src/tokenizer/char_ref/mod.rs
parentbaf1477c587fe22d27e94408cf2505d588ba007e (diff)
introduce Error enum
Diffstat (limited to 'src/tokenizer/char_ref/mod.rs')
-rw-r--r--src/tokenizer/char_ref/mod.rs39
1 files changed, 12 insertions, 27 deletions
diff --git a/src/tokenizer/char_ref/mod.rs b/src/tokenizer/char_ref/mod.rs
index 9c01bdf..4f94c88 100644
--- a/src/tokenizer/char_ref/mod.rs
+++ b/src/tokenizer/char_ref/mod.rs
@@ -8,10 +8,10 @@
// except according to those terms.
use super::{TokenSink, Tokenizer};
+use crate::error::{CharRefError, Error};
use crate::util::buffer_queue::BufferQueue;
use crate::util::str::is_ascii_alnum;
-use std::borrow::Cow::Borrowed;
use std::char::from_u32;
use self::State::*;
@@ -227,9 +227,7 @@ impl CharRefTokenizer {
) -> Status {
match unwrap_or_return!(tokenizer.peek(input), Stuck) {
';' => tokenizer.discard_char(input),
- _ => tokenizer.emit_error(Borrowed(
- "Semicolon missing after numeric character reference",
- )),
+ _ => tokenizer.emit_error(Error::CharRef(CharRefError::MissingSemicolon)),
};
self.finish_numeric(tokenizer)
}
@@ -246,7 +244,7 @@ impl CharRefTokenizer {
}
input.push_front(unconsume);
- tokenizer.emit_error(Borrowed("Numeric character reference without digits"));
+ tokenizer.emit_error(Error::CharRef(CharRefError::NumericCharRefWithoutDigits));
self.finish_none()
}
@@ -272,13 +270,9 @@ impl CharRefTokenizer {
};
if error {
- let msg = format_if!(
- tokenizer.opts.exact_errors,
- "Invalid numeric character reference",
- "Invalid numeric character reference value 0x{:06X}",
- self.num
- );
- tokenizer.emit_error(msg);
+ tokenizer.emit_error(Error::CharRef(CharRefError::NumericCharRefInvalid(
+ self.num,
+ )));
}
self.finish_one(c)
@@ -311,13 +305,7 @@ impl CharRefTokenizer {
#[cfg(feature = "named-entities")]
fn emit_name_error<Sink: TokenSink>(&mut self, tokenizer: &mut Tokenizer<Sink>) {
- let msg = format_if!(
- tokenizer.opts.exact_errors,
- "Invalid character reference",
- "Invalid character reference &{}",
- self.name_buf()
- );
- tokenizer.emit_error(msg);
+ tokenizer.emit_error(Error::CharRef(CharRefError::InvalidNamedCharRef));
}
fn unconsume_name(&mut self, input: &mut BufferQueue) {
@@ -384,16 +372,13 @@ impl CharRefTokenizer {
let unconsume_all = match (self.addnl_allowed, last_matched, next_after) {
(_, ';', _) => false,
(Some(_), _, Some('=')) => {
- tokenizer.emit_error(Borrowed(
- "Equals sign after character reference in attribute",
- ));
+ tokenizer
+ .emit_error(Error::CharRef(CharRefError::EqualsSignAfterCharRefInAttr));
true
}
(Some(_), _, Some(c)) if is_ascii_alnum(c) => true,
_ => {
- tokenizer.emit_error(Borrowed(
- "Character reference does not end with semicolon",
- ));
+ tokenizer.emit_error(Error::CharRef(CharRefError::MissingSemicolon));
false
}
};
@@ -444,7 +429,7 @@ impl CharRefTokenizer {
Numeric(_) if !self.seen_digit => drop(self.unconsume_numeric(tokenizer, input)),
Numeric(_) | NumericSemicolon => {
- tokenizer.emit_error(Borrowed("EOF in numeric character reference"));
+ tokenizer.emit_error(Error::CharRef(CharRefError::EofInNumericCharRef));
self.finish_numeric(tokenizer);
}
@@ -458,7 +443,7 @@ impl CharRefTokenizer {
Octothorpe => {
input.push_front(String::from("#"));
- tokenizer.emit_error(Borrowed("EOF after '#' in character reference"));
+ tokenizer.emit_error(Error::CharRef(CharRefError::EofAfterNumberSign));
self.finish_none();
}
}