aboutsummaryrefslogtreecommitdiffstats
path: root/src/construct/partial_bom.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-29 10:49:07 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-29 10:49:07 +0200
commit148ede7f0f42f0ccb1620b13d91f35d0c7d04c2f (patch)
tree7655ffebe0c6a917c3c391edacde03d754f2de4f /src/construct/partial_bom.rs
parent6f61649ac8d08fff85a99172afbf4cd852dda2e6 (diff)
downloadmarkdown-rs-148ede7f0f42f0ccb1620b13d91f35d0c7d04c2f.tar.gz
markdown-rs-148ede7f0f42f0ccb1620b13d91f35d0c7d04c2f.tar.bz2
markdown-rs-148ede7f0f42f0ccb1620b13d91f35d0c7d04c2f.zip
Refactor to work on bytes (`u8`)
Diffstat (limited to 'src/construct/partial_bom.rs')
-rw-r--r--src/construct/partial_bom.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/construct/partial_bom.rs b/src/construct/partial_bom.rs
new file mode 100644
index 0000000..be8d6c8
--- /dev/null
+++ b/src/construct/partial_bom.rs
@@ -0,0 +1,54 @@
+//! To do.
+
+use crate::token::Token;
+use crate::tokenizer::{State, Tokenizer};
+
+/// Before a BOM.
+///
+/// ```text
+/// > | 0xEF 0xBB 0xBF
+/// ^^^^
+/// ```
+pub fn start(tokenizer: &mut Tokenizer) -> State {
+ match tokenizer.current {
+ Some(0xEF) => {
+ tokenizer.enter(Token::ByteOrderMark);
+ tokenizer.consume();
+ State::Fn(Box::new(cont))
+ }
+ _ => State::Nok,
+ }
+}
+
+/// Second byte in BOM.
+///
+/// ```text
+/// > | 0xEF 0xBB 0xBF
+/// ^^^^
+/// ```
+fn cont(tokenizer: &mut Tokenizer) -> State {
+ match tokenizer.current {
+ Some(0xBB) => {
+ tokenizer.consume();
+ State::Fn(Box::new(end))
+ }
+ _ => State::Nok,
+ }
+}
+
+/// Last byte in BOM.
+///
+/// ```text
+/// > | 0xEF 0xBB 0xBF
+/// ^^^^
+/// ```
+fn end(tokenizer: &mut Tokenizer) -> State {
+ match tokenizer.current {
+ Some(0xBF) => {
+ tokenizer.consume();
+ tokenizer.exit(Token::ByteOrderMark);
+ State::Ok
+ }
+ _ => State::Nok,
+ }
+}