aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-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");
+ }
}