summaryrefslogtreecommitdiff
path: root/src/parsers/ini
diff options
context:
space:
mode:
Diffstat (limited to 'src/parsers/ini')
-rw-r--r--src/parsers/ini/mod.rs28
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(&current_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");
}
}
}