minify-html/rust/main/src/parse/comment.rs

26 lines
659 B
Rust
Raw Normal View History

2021-08-05 22:07:27 -04:00
use aho_corasick::AhoCorasick;
use lazy_static::lazy_static;
use crate::ast::NodeData;
use crate::parse::Code;
lazy_static! {
static ref COMMENT_END: AhoCorasick = AhoCorasick::new(&["-->"]);
}
2021-08-06 03:54:23 -04:00
pub fn parse_comment(code: &mut Code) -> NodeData {
debug_assert!(code.as_slice().starts_with(b"<!--"));
2021-08-05 22:07:27 -04:00
code.shift(4);
let (len, matched) = match COMMENT_END.find(code.as_slice()) {
2021-08-05 22:07:27 -04:00
Some(m) => (m.start(), m.end() - m.start()),
None => (code.rem(), 0),
};
let data = code.copy_and_shift(len);
// It might be EOF.
code.shift(matched);
NodeData::Comment {
code: data,
2021-08-06 02:17:45 -04:00
ended: matched > 0,
2021-08-05 22:07:27 -04:00
}
}