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
macro_rules! build {
($($t:tt)*) => {
v_escape::new!(
HTMLEscape,
"60->< || 62->> || 38->& || 34->" || 39->' || 47->/",
$($t)*
);
};
}
pub mod fallback {
build!(simd = false);
}
cfg_if::cfg_if! {
if #[cfg(all(v_htmlescape_simd, v_htmlescape_avx))] {
build!(simd = true, avx = true);
} else if #[cfg(all(v_htmlescape_simd, v_htmlescape_sse))] {
build!(simd = true, avx = false);
} else {
pub use self::fallback::*;
}
}
#[cfg(test)]
mod test {
#[test]
fn test_escape() {
use super::HTMLEscape;
let empty = "";
assert_eq!(HTMLEscape::from(empty).to_string(), empty);
assert_eq!(HTMLEscape::from("").to_string(), "");
assert_eq!(HTMLEscape::from("<&>").to_string(), "<&>");
assert_eq!(HTMLEscape::from("bar&").to_string(), "bar&");
assert_eq!(HTMLEscape::from("<foo").to_string(), "<foo");
assert_eq!(HTMLEscape::from("bar&h").to_string(), "bar&h");
assert_eq!(
HTMLEscape::from("// my <html> is \"unsafe\" & should be 'escaped'").to_string(),
"// my <html> is "unsafe" & \
should be 'escaped'"
);
assert_eq!(
HTMLEscape::from(
"// my <html> is \"unsafe\" & should be 'escaped'"
.repeat(10_000)
.as_ref()
)
.to_string(),
"// my <html> is "unsafe" & \
should be 'escaped'"
.repeat(10_000)
);
}
}