From 7247a2526cd449c90f2d4d83d13520035b663fae Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 7 Sep 2017 20:42:55 +0200 Subject: Rewrite escapable() to prevent duplication --- askama_shared/src/escaping.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/askama_shared/src/escaping.rs b/askama_shared/src/escaping.rs index a8a3559..99babfd 100644 --- a/askama_shared/src/escaping.rs +++ b/askama_shared/src/escaping.rs @@ -41,14 +41,17 @@ impl Display for MarkupDisplay where T: Display { } -fn escapable(b: &u8) -> bool { - *b == b'<' || *b == b'>' || *b == b'&' || *b == b'"' || *b == b'\'' || *b == b'/' +fn escapable(b: u8) -> bool { + match b { + b'<' | b'>' | b'&' | b'"' | b'\'' | b'/' => true, + _ => false, + } } pub fn escape(s: String) -> String { let mut found = Vec::new(); for (i, b) in s.as_bytes().iter().enumerate() { - if escapable(b) { + if escapable(*b) { found.push(i); } } -- cgit