Add tags_of_file() to extract tags from a File
This commit is contained in:
parent
a6ed8e1080
commit
42181afde5
1 changed files with 39 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
use storage::file::FileHeaderSpec as FHS;
|
use storage::file::FileHeaderSpec as FHS;
|
||||||
use storage::file::FileHeaderData as FHD;
|
use storage::file::FileHeaderData as FHD;
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
pub fn get_spec() -> FHS {
|
pub fn get_spec() -> FHS {
|
||||||
FHS::Map { keys: vec![ url_key(), tags_key() ] }
|
FHS::Map { keys: vec![ url_key(), tags_key() ] }
|
||||||
|
@ -38,3 +39,41 @@ fn build_tag_array(tags: &Vec<String>) -> FHD {
|
||||||
FHD::Array { values: Box::new(texttags) }
|
FHD::Array { values: Box::new(texttags) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_tags_from_header(header: &FHD) -> Vec<String> {
|
||||||
|
let mut tags : Vec<String> = vec![];
|
||||||
|
|
||||||
|
fn match_array(a: &Box<FHD>) -> Vec<String> {
|
||||||
|
let mut tags : Vec<String> = vec![];
|
||||||
|
|
||||||
|
match a.deref() {
|
||||||
|
&FHD::Array{values: ref vs} => {
|
||||||
|
let values : Vec<FHD> = 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<FHD> = 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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue