diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-09-07 20:42:55 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-09-07 20:42:55 +0200 |
commit | 7247a2526cd449c90f2d4d83d13520035b663fae (patch) | |
tree | e78db0ed4c80c9ce093fda36cbaa2a61350e7587 /askama_shared | |
parent | 7c29bf765fd666e61b9bc7d0eb40909b8e9002da (diff) | |
download | askama-7247a2526cd449c90f2d4d83d13520035b663fae.tar.gz askama-7247a2526cd449c90f2d4d83d13520035b663fae.tar.bz2 askama-7247a2526cd449c90f2d4d83d13520035b663fae.zip |
Rewrite escapable() to prevent duplication
Diffstat (limited to 'askama_shared')
-rw-r--r-- | askama_shared/src/escaping.rs | 9 |
1 files 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<T> Display for MarkupDisplay<T> 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); } } |