/// cleans the version number and the stuff in parans from a useragent, additionally makes it lowercause /// eg: `FooBot/99.0 (contact: foolium@foocorp.co)` -> `foobot` pub fn clean_useragent(useragent: &str) -> String { let mut s = useragent.trim().to_string(); if let Some(pos) = s.find('(') { s.truncate(pos); } if let Some(pos) = s.find('/') { s.truncate(pos); } let s = s.to_lowercase().trim().to_string(); return s; } #[cfg(test)] mod tests { #[test] fn clean_useragent_with_parans() { assert_eq!( super::clean_useragent("FooBot (contact: foolium@foocorp.co)"), "foobot" ) } #[test] fn clean_useragent_with_forward_slash() { assert_eq!(super::clean_useragent("FooBot/99.0"), "foobot") } #[test] fn clean_useragent_with_all() { assert_eq!( super::clean_useragent("FooBot/99.0 (contact: foolium@foocorp.co)"), "foobot" ) } }