Skip to content

Commit

Permalink
🆕 Add support for brackets in key-values
Browse files Browse the repository at this point in the history
  • Loading branch information
QEDK committed May 29, 2021
1 parent 72bc899 commit 1b63792
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/ini.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,18 +348,18 @@ impl Ini {
continue;
}
match trimmed.find('[') {
Some(start) => match trimmed.rfind(']') {
Some(0) => match trimmed.rfind(']') {
Some(end) => {
section = caser(trimmed[start + 1..end].trim());
section = caser(trimmed[1..end].trim());
}
None => {
return Err(format!(
"line {}:{}: Found opening bracket for section name but no closing bracket",
num, start
"line {}: Found opening bracket for section name but no closing bracket",
num
));
}
},
None => match trimmed.find(&self.delimiters[..]) {
Some(_) | None => match trimmed.find(&self.delimiters[..]) {
Some(delimiter) => match map.get_mut(&section) {
Some(valmap) => {
let key = caser(trimmed[..delimiter].trim());
Expand Down
1 change: 1 addition & 0 deletions tests/test.ini
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ KFC = the secret herb is orega-
colon:value after colon
Empty string =
None string
Password=[in-brackets]

[ spacing ]
indented=indented
Expand Down
2 changes: 2 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fn non_cs() -> Result<(), Box<dyn Error>> {
colon:value after colon
Empty string =
None string
Password=[in-brackets]
[ spacing ]
indented=indented
not indented = not indented ;testcomment
Expand Down Expand Up @@ -116,6 +117,7 @@ fn cs() -> Result<(), Box<dyn Error>> {
colon:value after colon
Empty string =
None string
Password=[in-brackets]
[ spacing ]
indented=indented
not indented = not indented ;testcomment
Expand Down

0 comments on commit 1b63792

Please sign in to comment.