From f28e8a59c781f24ed9399268cc2536aad0cf534d Mon Sep 17 00:00:00 2001 From: Benedict Börger Date: Sun, 14 Apr 2019 19:12:21 +0200 Subject: [global] update all files --- src/parsers/ini/mod.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'src/parsers/ini') diff --git a/src/parsers/ini/mod.rs b/src/parsers/ini/mod.rs index 9633231..5095344 100644 --- a/src/parsers/ini/mod.rs +++ b/src/parsers/ini/mod.rs @@ -4,17 +4,13 @@ use std::io::BufRead; use std::collections::HashMap; pub struct IniFile { - pub section : HashMap> -} - -pub struct IniSection { - pub section_name : String, - pub properties : HashMap> + // section_name, key, list of values + pub sections : HashMap>> } impl IniFile { pub fn from_file(path : &str) -> Result { - let mut file = HashMap::new(); + let mut file : HashMap>> = HashMap::new(); let fd = File::open(path)?; let reader = io::BufReader::new(fd); let mut current_section = String::from(""); @@ -38,7 +34,7 @@ impl IniFile { } current_section = n.to_string(); // TODO maybe the sections has been specified twice? - file.insert(n.to_string(), Vec::new() ); + file.insert(n.to_string(), HashMap::new() ); continue; } @@ -51,10 +47,22 @@ impl IniFile { if let Some(t) = kv.get(1) { value = t.to_string(); } + println!("key: {}, value: {}", key, value); if let Some(section) = file.get_mut(¤t_section) { - // get the entry with key from vector + println!("found current section"); + // get the values for key in section current_section + let mut hack_first = true; if let Some(ent) = section.get_mut(&key) { - ent.insert(value.to_string()); + println!("found key in map"); + ent.push(value.to_string()); + hack_first = false; + } + if hack_first { + let mut new = Vec::new(); + new.push(value.to_string()); + section.insert(key, new); + // TODO create new HashMap and insert + println!("inserted new one"); } } } -- cgit v1.2.3-70-g09d2