diff --git a/src/module/bm/header.rs b/src/module/bm/header.rs index 62c61a25..10f20d80 100644 --- a/src/module/bm/header.rs +++ b/src/module/bm/header.rs @@ -1,5 +1,6 @@ use storage::file::FileHeaderSpec as FHS; use storage::file::FileHeaderData as FHD; +use std::ops::Deref; pub fn get_spec() -> FHS { FHS::Map { keys: vec![ url_key(), tags_key() ] } @@ -38,3 +39,41 @@ fn build_tag_array(tags: &Vec) -> FHD { FHD::Array { values: Box::new(texttags) } } +pub fn get_tags_from_header(header: &FHD) -> Vec { + let mut tags : Vec = vec![]; + + fn match_array(a: &Box) -> Vec { + let mut tags : Vec = vec![]; + + match a.deref() { + &FHD::Array{values: ref vs} => { + let values : Vec = vs.deref().clone(); + for value in values { + match value { + FHD::Text(t) => tags.push(t), + _ => warn!("Malformed Header Data: Expected Text, found non-Text"), + } + } + } + _ => warn!("Malformed Header Data: Expected Array, found non-Array"), + } + + tags + } + + match header { + &FHD::Map{keys: ref ks} => { + let keys : Vec = ks.clone(); + for key in keys { + match key { + FHD::Key{name: _, value: ref v} => return match_array(v), + _ => warn!("Malformed Header Data: Expected Key, found non-Key"), + } + } + }, + _ => warn!("Malformed Header Data: Expected Map, found non-Map"), + } + + tags +} +