Skip to content

Commit

Permalink
Refactor:Implement two versions of load_from_files, one with case-ins…
Browse files Browse the repository at this point in the history
…ensitive and one without case-insensitive.
  • Loading branch information
cds committed Dec 5, 2024
1 parent 63ba0dc commit d2901d3
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,32 @@ impl Ini {
Ok(merged)
}

#[cfg(not(feature = "case-insensitive"))]
pub fn load_from_files<P: AsRef<Path>>(filenames: &Vec<P>) -> Result<Ini, Error> {
let mut merged = Ini::new();
let mut section_2_props: HashMap<Option<String>, Properties> = HashMap::new();
for filename in filenames {
match Ini::load_from_file(filename) {
Ok(ini) => {
for (section, props) in ini.sections {
if let Some(section_props) = section_2_props.get_mut(&section) {
for (key, value) in props {
section_props.insert(key, value);
}
} else {
section_2_props.insert(section, props);
}
}
}
Err(e) => return Err(e),
}
}
for (section, props) in section_2_props {
merged.sections.insert(section, props);
}
Ok(merged)
}

/// Load from a file, but do not interpret '\' as an escape character
pub fn load_from_file_noescape<P: AsRef<Path>>(filename: P) -> Result<Ini, Error> {
Ini::load_from_file_opt(
Expand Down Expand Up @@ -2826,7 +2852,6 @@ bla = a
}

#[test]
#[cfg(feature = "case-insensitive")]
fn test_load_from_files() {
//Test both overwrite and append

Expand Down

0 comments on commit d2901d3

Please sign in to comment.