simplify creating XmlAut
This commit is contained in:
parent
247591707d
commit
c6252464aa
1 changed files with 16 additions and 33 deletions
49
src/epub.rs
49
src/epub.rs
|
@ -96,6 +96,16 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
|
||||||
role: String,
|
role: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl XmlAut {
|
||||||
|
fn new() -> Self {
|
||||||
|
XmlAut {
|
||||||
|
name: String::new(),
|
||||||
|
sort: String::new(),
|
||||||
|
role: String::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut xml_authors = HashMap::new();
|
let mut xml_authors = HashMap::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@ -121,14 +131,7 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
|
||||||
+ String::from_utf8(idval.unwrap().value.to_vec())
|
+ String::from_utf8(idval.unwrap().value.to_vec())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_str();
|
.as_str();
|
||||||
xml_authors.insert(
|
xml_authors.insert(curr_id.clone(), XmlAut::new());
|
||||||
curr_id.clone(),
|
|
||||||
XmlAut {
|
|
||||||
name: "".to_string(),
|
|
||||||
sort: "".to_string(),
|
|
||||||
role: "".to_string(),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if let Some(file_as_val) = e
|
if let Some(file_as_val) = e
|
||||||
|
@ -139,11 +142,7 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
|
||||||
let ns =
|
let ns =
|
||||||
String::from_utf8(file_as_val.as_ref().unwrap().key.to_vec()).unwrap();
|
String::from_utf8(file_as_val.as_ref().unwrap().key.to_vec()).unwrap();
|
||||||
curr_id = "none".to_string() + ns.split(':').collect::<Vec<&str>>()[0];
|
curr_id = "none".to_string() + ns.split(':').collect::<Vec<&str>>()[0];
|
||||||
let entry = xml_authors.entry(curr_id.clone()).or_insert(XmlAut {
|
let entry = xml_authors.entry(curr_id.clone()).or_insert(XmlAut::new());
|
||||||
name: "".to_string(),
|
|
||||||
sort: "".to_string(),
|
|
||||||
role: "".to_string(),
|
|
||||||
});
|
|
||||||
entry.sort = file_as_val
|
entry.sort = file_as_val
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unescape_and_decode_value(&reader)
|
.unescape_and_decode_value(&reader)
|
||||||
|
@ -163,18 +162,10 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
|
||||||
}
|
}
|
||||||
Ok(Event::Text(ref e)) if creator_found => {
|
Ok(Event::Text(ref e)) if creator_found => {
|
||||||
if is_epub3 {
|
if is_epub3 {
|
||||||
let entry = xml_authors.entry(curr_id.clone()).or_insert(XmlAut {
|
let entry = xml_authors.entry(curr_id.clone()).or_insert(XmlAut::new());
|
||||||
name: "".to_string(),
|
|
||||||
sort: "".to_string(),
|
|
||||||
role: "".to_string(),
|
|
||||||
});
|
|
||||||
entry.name = String::from_utf8(e.to_vec()).unwrap();
|
entry.name = String::from_utf8(e.to_vec()).unwrap();
|
||||||
} else {
|
} else {
|
||||||
let entry = xml_authors.entry(curr_id.clone()).or_insert(XmlAut {
|
let entry = xml_authors.entry(curr_id.clone()).or_insert(XmlAut::new());
|
||||||
name: "".to_string(),
|
|
||||||
sort: "".to_string(),
|
|
||||||
role: "".to_string(),
|
|
||||||
});
|
|
||||||
entry.name = String::from_utf8(e.to_vec()).unwrap();
|
entry.name = String::from_utf8(e.to_vec()).unwrap();
|
||||||
entry.role = "aut".to_string();
|
entry.role = "aut".to_string();
|
||||||
}
|
}
|
||||||
|
@ -203,21 +194,13 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Event::Text(ref e)) if file_as_found && is_epub3 => {
|
Ok(Event::Text(ref e)) if file_as_found && is_epub3 => {
|
||||||
let entry = xml_authors.entry(curr_id.clone()).or_insert(XmlAut {
|
let entry = xml_authors.entry(curr_id.clone()).or_insert(XmlAut::new());
|
||||||
name: "".to_string(),
|
|
||||||
sort: "".to_string(),
|
|
||||||
role: "".to_string(),
|
|
||||||
});
|
|
||||||
entry.sort = String::from_utf8(e.to_vec()).unwrap();
|
entry.sort = String::from_utf8(e.to_vec()).unwrap();
|
||||||
|
|
||||||
file_as_found = false;
|
file_as_found = false;
|
||||||
}
|
}
|
||||||
Ok(Event::Text(ref e)) if role_found && is_epub3 => {
|
Ok(Event::Text(ref e)) if role_found && is_epub3 => {
|
||||||
let entry = xml_authors.entry(curr_id.clone()).or_insert(XmlAut {
|
let entry = xml_authors.entry(curr_id.clone()).or_insert(XmlAut::new());
|
||||||
name: "".to_string(),
|
|
||||||
sort: "".to_string(),
|
|
||||||
role: "".to_string(),
|
|
||||||
});
|
|
||||||
entry.role = String::from_utf8(e.to_vec()).unwrap();
|
entry.role = String::from_utf8(e.to_vec()).unwrap();
|
||||||
|
|
||||||
role_found = false;
|
role_found = false;
|
||||||
|
|
Loading…
Reference in a new issue