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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use super::{Mutations, Token};
use crate::base::Bytes;
use crate::rewritable_units::ContentType;
use encoding_rs::Encoding;
use std::fmt::{self, Debug};
pub struct EndTag<'i> {
name: Bytes<'i>,
raw: Option<Bytes<'i>>,
encoding: &'static Encoding,
pub(crate) mutations: Mutations,
}
impl<'i> EndTag<'i> {
pub(super) fn new_token(
name: Bytes<'i>,
raw: Bytes<'i>,
encoding: &'static Encoding,
) -> Token<'i> {
Token::EndTag(EndTag {
name,
raw: Some(raw),
encoding,
mutations: Mutations::new(encoding),
})
}
#[inline]
pub fn name(&self) -> String {
self.name.as_lowercase_string(self.encoding)
}
#[inline]
pub fn set_name(&mut self, name: Bytes<'static>) {
self.name = name;
self.raw = None;
}
#[inline]
pub fn set_name_str(&mut self, name: String) {
self.set_name(Bytes::from_string(name, self.encoding))
}
#[inline]
pub fn before(&mut self, content: &str, content_type: ContentType) {
self.mutations.before(content, content_type);
}
#[inline]
pub fn after(&mut self, content: &str, content_type: ContentType) {
self.mutations.after(content, content_type);
}
#[inline]
pub fn replace(&mut self, content: &str, content_type: ContentType) {
self.mutations.replace(content, content_type);
}
#[inline]
pub fn remove(&mut self) {
self.mutations.remove();
}
#[inline]
fn raw(&self) -> Option<&Bytes> {
self.raw.as_ref()
}
#[inline]
fn serialize_from_parts(&self, output_handler: &mut dyn FnMut(&[u8])) {
output_handler(b"</");
output_handler(&self.name);
output_handler(b">");
}
}
impl_serialize!(EndTag);
impl Debug for EndTag<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("EndTag")
.field("name", &self.name())
.finish()
}
}