aboutsummaryrefslogtreecommitdiffstats
path: root/src/construct/partial_bom.rs
blob: 155a1a39a72212724e139ab3b6eaa8578106195b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! 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 {
    if tokenizer.current == Some(0xEF) {
        tokenizer.enter(Token::ByteOrderMark);
        tokenizer.consume();
        State::Fn(Box::new(cont))
    } else {
        State::Nok
    }
}

/// Second byte in BOM.
///
/// ```text
/// > | 0xEF 0xBB 0xBF
///          ^^^^
/// ```
fn cont(tokenizer: &mut Tokenizer) -> State {
    if tokenizer.current == Some(0xBB) {
        tokenizer.consume();
        State::Fn(Box::new(end))
    } else {
        State::Nok
    }
}

/// Last byte in BOM.
///
/// ```text
/// > | 0xEF 0xBB 0xBF
///               ^^^^
/// ```
fn end(tokenizer: &mut Tokenizer) -> State {
    if tokenizer.current == Some(0xBF) {
        tokenizer.consume();
        tokenizer.exit(Token::ByteOrderMark);
        State::Ok
    } else {
        State::Nok
    }
}