Skip to content

Commit

Permalink
store List attributes in dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarzik committed Feb 16, 2024
1 parent 95dc498 commit 783fd2c
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ enum PccTag {

pub struct PccList {
_ident: String,
_attrib: Vec<(String, String)>,
attrib: Vec<(String, String)>,
}

impl PccList {
pub fn new(ident: &str) -> PccList {
PccList {
_ident: String::from(ident),
_attrib: Vec::new(),
attrib: Vec::new(),
}
}
}
Expand All @@ -58,6 +58,15 @@ pub enum PccDatum {
List(PccList),
}

impl PccDatum {
pub fn as_mut_list(&mut self) -> Option<&mut PccList> {
match self {
PccDatum::List(l) => Some(l),
_ => None,
}
}
}

#[derive(Clone)]
pub struct PccConfig {
datadir: String,
Expand Down Expand Up @@ -150,9 +159,9 @@ impl Pcc {
}

// Read a single LST record
fn read_lst_line(&mut self, _datum: &mut PccDatum, line: &str) -> io::Result<()> {
let mut tags: Vec<&str> = line.split('\t').collect();
let raw_ident = tags.remove(0);
fn read_lst_line(&mut self, datum: &mut PccDatum, line: &str) -> io::Result<()> {
let mut attribs: Vec<&str> = line.split('\t').collect();
let raw_ident = attribs.remove(0);
let is_mod = raw_ident.ends_with(".MOD");
let ident;
if is_mod {
Expand All @@ -161,8 +170,25 @@ impl Pcc {
ident = &raw_ident;
}

let lst = datum.as_mut_list().unwrap();

println!("ID={}, is_mod {}", ident, is_mod);

for attrib in &attribs {
match attrib.split_once(':') {
None => {
if !attrib.trim().is_empty() {
println!("\t{}", attrib);
lst.attrib.push((attrib.to_string(), String::from("")));
}
}
Some((akey, aval)) => {
println!("\t{}={}", akey, aval);
lst.attrib.push((akey.to_string(), aval.to_string()));
}
}
}

Ok(())
}

Expand Down

0 comments on commit 783fd2c

Please sign in to comment.