Module helpers: header: Add get_url_from_header()

This commit is contained in:
Matthias Beyer 2015-12-28 12:15:05 +01:00
parent 24e1ea2522
commit c6f31496ab
2 changed files with 32 additions and 1 deletions

View File

@ -4,3 +4,35 @@
pub mod tags;
pub mod data {
use std::ops::Deref;
use storage::file::header::data::FileHeaderData as FHD;
pub fn get_url_from_header(header: &FHD) -> Option<String> {
match header {
&FHD::Map{keys: ref ks} => {
let mut keys : Vec<FHD> = ks.clone();
keys.iter().find(|k| {
match k.deref() {
&FHD::Key{name: ref n, value: ref v} => n == "URL",
_ => false
}
}).and_then(|urlkey| {
match urlkey.deref().clone() {
FHD::Text(s) => Some(s),
_ => {
warn!("Malformed Header Data: Expected Text, found non-Text");
None
},
}
})
},
_ => {
warn!("Malformed Header Data: Expected Map, found non-Map");
None
}
}
}
}

View File

@ -63,6 +63,5 @@ pub mod data {
tags
}
}