From 6f9fc729eba8a02218f9f09a7a9d114cd6fcc34d Mon Sep 17 00:00:00 2001 From: Andy Librian Date: Sat, 11 Mar 2017 21:23:02 +0700 Subject: added trim filter (#18) --- askama/src/filters.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/askama/src/filters.rs b/askama/src/filters.rs index bd64bb0..62f2616 100644 --- a/askama/src/filters.rs +++ b/askama/src/filters.rs @@ -79,6 +79,12 @@ pub fn uppercase(s: &fmt::Display) -> String { upper(s) } +/// Strip leading and trailing whitespace. +pub fn trim(s: &fmt::Display) -> String { + let s = format!("{}", s); + s.trim().to_owned() +} + #[cfg(test)] mod tests { use super::*; @@ -99,4 +105,9 @@ mod tests { assert_eq!(upper(&"FooBar"), "FOOBAR"); assert_eq!(upper(&"foo"), "FOO"); } + + #[test] + fn test_trim() { + assert_eq!(trim(&" Hello\tworld\t"), "Hello\tworld"); + } } -- cgit