aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Andy Librian <andylibrian@gmail.com>2017-03-11 21:23:02 +0700
committerLibravatar Andy Librian <andylibrian@gmail.com>2017-03-11 21:23:02 +0700
commit6f9fc729eba8a02218f9f09a7a9d114cd6fcc34d (patch)
tree829a3b421ddd67f99551c7668878f6b334d27a33
parent7362ca0dcb61ec70ad88f74873f459702c5c0dde (diff)
downloadaskama-6f9fc729eba8a02218f9f09a7a9d114cd6fcc34d.tar.gz
askama-6f9fc729eba8a02218f9f09a7a9d114cd6fcc34d.tar.bz2
askama-6f9fc729eba8a02218f9f09a7a9d114cd6fcc34d.zip
added trim filter (#18)
-rw-r--r--askama/src/filters.rs11
1 files changed, 11 insertions, 0 deletions
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");
+ }
}