Skip to content

Commit

Permalink
Support parsing ini files with inline comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortham committed Nov 7, 2023
1 parent cd2de4f commit f27eaa4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ esplugin = "4.1.0"
regex = "1.0.0"
unicase = "2.0.0"
rayon = "1.0.0"
rust-ini = { version = "0.20.0", features = ["case-insensitive"] }
rust-ini = { version = "0.20.0", features = ["case-insensitive", "inline-comment"] }
keyvalues-parser = "0.2.0"

[target.'cfg(windows)'.dependencies]
Expand Down
19 changes: 19 additions & 0 deletions src/ini.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,25 @@ mod tests {
assert_eq!(None, ini.get_from(Some("General"), "sTestFile4"));
}

#[test]
fn read_ini_should_support_inline_comments() {
let tmp_dir = tempdir().unwrap();
let game_path = tmp_dir.path();
let ini_path = game_path.join("Oblivion.ini");

std::fs::write(
&ini_path,
"[General]\nsTestFile1=a #comment\nSTestFile2=b ;comment\nsTestFile3=c",
)
.unwrap();

let ini = read_ini(&ini_path).unwrap();

assert_eq!(Some("a"), ini.get_from(Some("General"), "sTestFile1"));
assert_eq!(Some("b"), ini.get_from(Some("General"), "sTestFile2"));
assert_eq!(Some("c"), ini.get_from(Some("General"), "sTestFile3"));
}

#[test]
fn read_ini_should_read_as_windows_1252() {
let tmp_dir = tempdir().unwrap();
Expand Down

0 comments on commit f27eaa4

Please sign in to comment.