diff --git a/src/caps.rs b/src/caps.rs index 4b504241..b7753a19 100644 --- a/src/caps.rs +++ b/src/caps.rs @@ -91,8 +91,9 @@ fn compute_features(features: &[Feature]) -> Vec { fn compute_identities(identities: &[Identity]) -> Vec { compute_items(identities, |identity| { - let empty = String::new(); - let string = format!("{}/{}/{}/{}", identity.category, identity.type_, identity.xml_lang, match identity.name { Some(ref name) => name, None => &empty }); + let lang = identity.lang.clone().unwrap_or_default(); + let name = identity.name.clone().unwrap_or_default(); + let string = format!("{}/{}/{}/{}", identity.category, identity.type_, lang, name); let bytes = string.as_bytes(); let mut vec = Vec::with_capacity(bytes.len()); vec.extend_from_slice(bytes); diff --git a/src/disco.rs b/src/disco.rs index 46d25dec..486f81e9 100644 --- a/src/disco.rs +++ b/src/disco.rs @@ -37,7 +37,7 @@ impl IntoElements for Feature { pub struct Identity { pub category: String, // TODO: use an enum here. pub type_: String, // TODO: use an enum here. - pub xml_lang: String, + pub lang: Option, pub name: Option, } @@ -47,7 +47,7 @@ impl Into for Identity { .ns(ns::DISCO_INFO) .attr("category", self.category) .attr("type", self.type_) - .attr("xml:lang", self.xml_lang) + .attr("xml:lang", self.lang) .attr("name", self.name) .build() } @@ -98,12 +98,12 @@ impl TryFrom for Disco { return Err(Error::ParseError("Identity must have a non-empty 'type' attribute.")) } - let lang = get_attr!(child, "xml:lang", default); + let lang = get_attr!(child, "xml:lang", optional); let name = get_attr!(child, "name", optional); identities.push(Identity { category: category, type_: type_, - xml_lang: lang, + lang: lang, name: name, }); } else if child.is("x", ns::DATA_FORMS) { diff --git a/src/ecaps2.rs b/src/ecaps2.rs index 09f1516e..7d9279bb 100644 --- a/src/ecaps2.rs +++ b/src/ecaps2.rs @@ -88,7 +88,7 @@ fn compute_identities(identities: &[Identity]) -> Vec { compute_items(identities, 0x1c, |identity| { let mut bytes = compute_item(&identity.category); bytes.append(&mut compute_item(&identity.type_)); - bytes.append(&mut compute_item(&identity.xml_lang)); + bytes.append(&mut compute_item(&identity.lang.clone().unwrap_or_default())); bytes.append(&mut compute_item(&identity.name.clone().unwrap_or_default())); bytes.push(0x1e); bytes