Skip to content

Commit 02e06dc

Browse files
LostSnail42zonyitoo
LostSnail42
authored andcommitted
Add support for custom key-value separator in nameless sections.
1 parent e505047 commit 02e06dc

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ impl Ini {
810810
for (k, v) in props.iter() {
811811
let k_str = escape_str(k, opt.escape_policy);
812812
let v_str = escape_str(v, opt.escape_policy);
813-
write!(writer, "{}={}{}", k_str, v_str, opt.line_separator)?;
813+
write!(writer, "{}{}{}{}", k_str, opt.kv_separator, v_str, opt.line_separator)?;
814814

815815
firstline = false;
816816
}
@@ -2119,6 +2119,9 @@ a3 = n3
21192119
use std::str;
21202120

21212121
let mut ini = Ini::new();
2122+
ini.with_section(None::<String>)
2123+
.set("Key1", "Value")
2124+
.set("Key2", "Value");
21222125
ini.with_section(Some("Section1"))
21232126
.set("Key1", "Value")
21242127
.set("Key2", "Value");
@@ -2139,12 +2142,12 @@ a3 = n3
21392142
// Test different line endings in Windows and Unix
21402143
if cfg!(windows) {
21412144
assert_eq!(
2142-
"[Section1]\r\nKey1 = Value\r\nKey2 = Value\r\n\r\n[Section2]\r\nKey1 = Value\r\nKey2 = Value\r\n",
2145+
"Key1 = Value\r\nKey2 = Value\r\n\r\n[Section1]\r\nKey1 = Value\r\nKey2 = Value\r\n\r\n[Section2]\r\nKey1 = Value\r\nKey2 = Value\r\n",
21432146
str::from_utf8(&buf).unwrap()
21442147
);
21452148
} else {
21462149
assert_eq!(
2147-
"[Section1]\nKey1 = Value\nKey2 = Value\n\n[Section2]\nKey1 = Value\nKey2 = Value\n",
2150+
"Key1 = Value\nKey2 = Value\n\n[Section1]\nKey1 = Value\nKey2 = Value\n\n[Section2]\nKey1 = Value\nKey2 = Value\n",
21482151
str::from_utf8(&buf).unwrap()
21492152
);
21502153
}

0 commit comments

Comments
 (0)