project to map out webrings
at main 1.0 kB view raw
1/// cleans the version number and the stuff in parans from a useragent, additionally makes it lowercause 2/// eg: `FooBot/99.0 (contact: foolium@foocorp.co)` -> `foobot` 3pub fn clean_useragent(useragent: &str) -> String { 4 let mut s = useragent.trim().to_string(); 5 6 if let Some(pos) = s.find('(') { 7 s.truncate(pos); 8 } 9 10 if let Some(pos) = s.find('/') { 11 s.truncate(pos); 12 } 13 14 let s = s.to_lowercase().trim().to_string(); 15 16 return s; 17} 18 19#[cfg(test)] 20mod tests { 21 #[test] 22 fn clean_useragent_with_parans() { 23 assert_eq!( 24 super::clean_useragent("FooBot (contact: foolium@foocorp.co)"), 25 "foobot" 26 ) 27 } 28 29 #[test] 30 fn clean_useragent_with_forward_slash() { 31 assert_eq!(super::clean_useragent("FooBot/99.0"), "foobot") 32 } 33 34 #[test] 35 fn clean_useragent_with_all() { 36 assert_eq!( 37 super::clean_useragent("FooBot/99.0 (contact: foolium@foocorp.co)"), 38 "foobot" 39 ) 40 } 41}