disco: Make xml:lang a proper Option and rename it to lang.
This commit is contained in:
parent
d1a7d222f0
commit
8e1d5e7983
3 changed files with 8 additions and 7 deletions
|
|
@ -91,8 +91,9 @@ fn compute_features(features: &[Feature]) -> Vec<u8> {
|
||||||
|
|
||||||
fn compute_identities(identities: &[Identity]) -> Vec<u8> {
|
fn compute_identities(identities: &[Identity]) -> Vec<u8> {
|
||||||
compute_items(identities, |identity| {
|
compute_items(identities, |identity| {
|
||||||
let empty = String::new();
|
let lang = identity.lang.clone().unwrap_or_default();
|
||||||
let string = format!("{}/{}/{}/{}", identity.category, identity.type_, identity.xml_lang, match identity.name { Some(ref name) => name, None => &empty });
|
let name = identity.name.clone().unwrap_or_default();
|
||||||
|
let string = format!("{}/{}/{}/{}", identity.category, identity.type_, lang, name);
|
||||||
let bytes = string.as_bytes();
|
let bytes = string.as_bytes();
|
||||||
let mut vec = Vec::with_capacity(bytes.len());
|
let mut vec = Vec::with_capacity(bytes.len());
|
||||||
vec.extend_from_slice(bytes);
|
vec.extend_from_slice(bytes);
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ impl IntoElements for Feature {
|
||||||
pub struct Identity {
|
pub struct Identity {
|
||||||
pub category: String, // TODO: use an enum here.
|
pub category: String, // TODO: use an enum here.
|
||||||
pub type_: String, // TODO: use an enum here.
|
pub type_: String, // TODO: use an enum here.
|
||||||
pub xml_lang: String,
|
pub lang: Option<String>,
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,7 +47,7 @@ impl Into<Element> for Identity {
|
||||||
.ns(ns::DISCO_INFO)
|
.ns(ns::DISCO_INFO)
|
||||||
.attr("category", self.category)
|
.attr("category", self.category)
|
||||||
.attr("type", self.type_)
|
.attr("type", self.type_)
|
||||||
.attr("xml:lang", self.xml_lang)
|
.attr("xml:lang", self.lang)
|
||||||
.attr("name", self.name)
|
.attr("name", self.name)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
@ -98,12 +98,12 @@ impl TryFrom<Element> for Disco {
|
||||||
return Err(Error::ParseError("Identity must have a non-empty 'type' attribute."))
|
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);
|
let name = get_attr!(child, "name", optional);
|
||||||
identities.push(Identity {
|
identities.push(Identity {
|
||||||
category: category,
|
category: category,
|
||||||
type_: type_,
|
type_: type_,
|
||||||
xml_lang: lang,
|
lang: lang,
|
||||||
name: name,
|
name: name,
|
||||||
});
|
});
|
||||||
} else if child.is("x", ns::DATA_FORMS) {
|
} else if child.is("x", ns::DATA_FORMS) {
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ fn compute_identities(identities: &[Identity]) -> Vec<u8> {
|
||||||
compute_items(identities, 0x1c, |identity| {
|
compute_items(identities, 0x1c, |identity| {
|
||||||
let mut bytes = compute_item(&identity.category);
|
let mut bytes = compute_item(&identity.category);
|
||||||
bytes.append(&mut compute_item(&identity.type_));
|
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.append(&mut compute_item(&identity.name.clone().unwrap_or_default()));
|
||||||
bytes.push(0x1e);
|
bytes.push(0x1e);
|
||||||
bytes
|
bytes
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue