diff --git a/parsers/src/bob.rs b/parsers/src/bob.rs index 40cbd3df7e2457cc0684726baea325c3716a8f32..b29eb5f4a462a5ac4fa98c2d11b38fdc6ac58e4f 100644 --- a/parsers/src/bob.rs +++ b/parsers/src/bob.rs @@ -26,26 +26,15 @@ impl FromStr for ContentId { type Err = Error; fn from_str(s: &str) -> Result { - let temp: Vec<_> = s.splitn(2, '@').collect(); - let temp: Vec<_> = match temp[..] { - [lhs, rhs] => { - if rhs != "bob.xmpp.org" { - return Err(Error::Other("Wrong domain for cid URI.")); - } - lhs.splitn(2, '+').collect() - } - _ => return Err(Error::Other("Missing @ in cid URI.")), - }; - let (algo, hex) = match temp[..] { - [lhs, rhs] => { - let algo = match lhs { - "sha1" => Algo::Sha_1, - "sha256" => Algo::Sha_256, - _ => unimplemented!(), - }; - (algo, rhs) - } - _ => return Err(Error::Other("Missing + in cid URI.")), + let (lhs, rhs) = s.split_once('@').ok_or(Error::Other("Missing @ in cid URI."))?; + if rhs != "bob.xmpp.org" { + return Err(Error::Other("Wrong domain for cid URI.")); + } + let (algo, hex) = lhs.split_once('+').ok_or(Error::Other("Missing + in cid URI."))?; + let algo = match algo { + "sha1" => Algo::Sha_1, + "sha256" => Algo::Sha_256, + _ => unimplemented!(), }; let hash = Hash::from_hex(algo, hex).map_err(Error::text_parse_error)?; Ok(ContentId { hash }) diff --git a/parsers/src/xhtml.rs b/parsers/src/xhtml.rs index 8f0561c2336aff566129dd321dc81df7758ac5a4..e3948bc83f6097cf2b22a738a59dbc0181d27516 100644 --- a/parsers/src/xhtml.rs +++ b/parsers/src/xhtml.rs @@ -169,9 +169,7 @@ impl TryFrom for Body { Ok(Body { style: parse_css(elem.attr("style")), - xml_lang: elem - .attr_ns("xml", "lang") - .map(ToString::to_string), + xml_lang: elem.attr_ns("xml", "lang").map(ToString::to_string), children, }) } @@ -502,14 +500,12 @@ fn parse_css(style: Option<&str>) -> Css { let mut properties = vec![]; if let Some(style) = style { // TODO: make that parser a bit more resilient to things. - for part in style.split(';') { - let mut part = part - .splitn(2, ':') - .map(ToString::to_string) - .collect::>(); - let key = part.pop().unwrap(); - let value = part.pop().unwrap(); - properties.push(Property { key, value }); + for declaration in style.split(';') { + let (key, value) = declaration.split_once(':').unwrap(); + properties.push(Property { + key: key.to_string(), + value: value.to_string(), + }); } } properties