rewrite is_bad_tag with matches! macro
Removing String allocation in iterator.
This commit is contained in:
14
src/lib.rs
14
src/lib.rs
@@ -10,9 +10,7 @@ fn decode_named_entity(entity: &str) -> Option<char> {
|
|||||||
.ok()
|
.ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
const BAD_TAGS: [&str; 4] = ["head", "script", "style", "a"];
|
/// Tries to parse a link and returns the location it leads to.
|
||||||
|
|
||||||
// awkward
|
|
||||||
fn parse_link(l: &str) -> Option<&str> {
|
fn parse_link(l: &str) -> Option<&str> {
|
||||||
let href_value = l
|
let href_value = l
|
||||||
.strip_prefix('a')?
|
.strip_prefix('a')?
|
||||||
@@ -40,11 +38,11 @@ fn parse_link(l: &str) -> Option<&str> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_bad_tag(t: &str) -> bool {
|
fn is_bad_tag(t: &str) -> bool {
|
||||||
let t = t.split_whitespace().next().unwrap();
|
let t = t.trim();
|
||||||
if BAD_TAGS.contains(&t) {
|
matches!(
|
||||||
return true;
|
t.split_once(char::is_whitespace).map_or(t, |(t, _)| t),
|
||||||
}
|
"head" | "script" | "style" | "a"
|
||||||
false
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// replacing regex
|
// replacing regex
|
||||||
|
|||||||
Reference in New Issue
Block a user