nanohtml2text

Lightweight html to text converter in Rust
git clone git://git.alexwennerberg.com/nanohtml2text
Log | Files | Refs | LICENSE

commit a18add05fbac6a6396052cc0b3e795d3c489d32f
parent 00a9b04d903ba7c6e04dc0b055f32763c781bd11
Author: Johann150 <johann.galle@protonmail.com>
Date:   Wed, 12 Jan 2022 22:47:14 +0100

rewrite is_bad_tag with matches! macro

Removing String allocation in iterator.

Diffstat:
Msrc/lib.rs | 14++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/lib.rs b/src/lib.rs @@ -10,9 +10,7 @@ fn decode_named_entity(entity: &str) -> Option<char> { .ok() } -const BAD_TAGS: [&str; 4] = ["head", "script", "style", "a"]; - -// awkward +/// Tries to parse a link and returns the location it leads to. fn parse_link(l: &str) -> Option<&str> { let href_value = l .strip_prefix('a')? @@ -40,11 +38,11 @@ fn parse_link(l: &str) -> Option<&str> { } fn is_bad_tag(t: &str) -> bool { - let t = t.split_whitespace().next().unwrap(); - if BAD_TAGS.contains(&t) { - return true; - } - false + let t = t.trim(); + matches!( + t.split_once(char::is_whitespace).map_or(t, |(t, _)| t), + "head" | "script" | "style" | "a" + ) } // replacing regex