added trim filter (#18)

This commit is contained in:
Andy Librian 2017-03-11 21:23:02 +07:00
parent 7362ca0dcb
commit 6f9fc729eb

View File

@ -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");
}
}