diff options
| author | Benedict Börger <benedict@0xb8000.de> | 2019-04-14 19:12:21 +0200 |
|---|---|---|
| committer | Benedict Börger <benedict@0xb8000.de> | 2019-04-14 19:12:21 +0200 |
| commit | f28e8a59c781f24ed9399268cc2536aad0cf534d (patch) | |
| tree | 5678dd6c12b5849ab15f9d63a49c9424d222390b /src/parsers/ini | |
| parent | 7e8656cb6d086f364baeeb79a69a04555a6fd4f6 (diff) | |
[global] update all files
Diffstat (limited to 'src/parsers/ini')
| -rw-r--r-- | src/parsers/ini/mod.rs | 28 |
1 files changed, 18 insertions, 10 deletions
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<String, Vec<IniSection>> -} - -pub struct IniSection { - pub section_name : String, - pub properties : HashMap<String, Vec<String>> + // section_name, key, list of values + pub sections : HashMap<String, HashMap<String, Vec<String>>> } impl IniFile { pub fn from_file(path : &str) -> Result<IniFile, io::Error> { - let mut file = HashMap::new(); + let mut file : HashMap<String, HashMap<String,Vec<String>>> = 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"); } } } |
