Skip to content

Commit

Permalink
Support duplicated sections and case insensitive keys
Browse files Browse the repository at this point in the history
ref #49, #61
  • Loading branch information
zonyitoo committed Jan 28, 2020
1 parent a193a51 commit a1a568b
Show file tree
Hide file tree
Showing 6 changed files with 408 additions and 295 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ cache: cargo

script:
- cargo test -v --no-fail-fast
- cargo test -v --no-fail-fast --features preserve_order
- cargo test -v --no-fail-fast --features inline_comment
- cargo test -v --no-fail-fast --features inline-comment
- cargo test -v --no-fail-fast --features case-insensitive
- cargo doc --no-deps
13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rust-ini"
version = "0.14.0"
version = "0.15.0"
authors = ["Y. T. Chung <[email protected]>"]
description = "An Ini configuration file parsing library in Rust"
repository = "https://github.com/zonyitoo/rust-ini"
Expand All @@ -14,13 +14,12 @@ name = "ini"
test = true

[dependencies]
multimap = "0.8"
indexmap = { version = "1.3", optional = true }
cfg-if = "0.1"
unicase = { version = "2.6", optional = true }
ordered-multimap = { version = "0.2" }

[features]
default = []
# Sections and Properties will preserve order of keys in the original input
preserve_order = ["indexmap"]
# Allowing inline comments
#
# For example:
Expand All @@ -29,4 +28,6 @@ preserve_order = ["indexmap"]
# Key=value # COMMENTS
#
# This was a default feature < 0.14.0
inline_comment = []
inline-comment = []
# Case-insensitive Sections and Property Keys
case-insensitive = ["unicase"]
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This is an INI file parser in Rust_.
.. code:: toml
[dependencies]
rust-ini = "0.14"
rust-ini = "0.15"
Usage
=====
Expand All @@ -37,11 +37,11 @@ Usage
let mut conf = Ini::new();
conf.with_section(None)
.set("encoding", "utf-8");
conf.with_section(Some("User".to_owned()))
conf.with_section(Some("User"))
.set("given_name", "Tommy")
.set("family_name", "Green")
.set("unicode", "Raspberry树莓");
conf.with_section(Some("Book".to_owned()))
conf.with_section(Some("Book"))
.set("name", "Rust cool");
conf.write_to_file("conf.ini").unwrap();
}
Expand Down Expand Up @@ -70,7 +70,7 @@ Then you will get ``conf.ini``
fn main() {
let conf = Ini::load_from_file("conf.ini").unwrap();
let section = conf.section(Some("User".to_owned())).unwrap();
let section = conf.section(Some("User")).unwrap();
let tommy = section.get("given_name").unwrap();
let green = section.get("family_name").unwrap();
Expand Down
6 changes: 3 additions & 3 deletions examples/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ fn main() {
let i = Ini::load_from_file(CONF_FILE_NAME).unwrap();

println!("Iterating");
let general_section_name = "__General__".into();
let general_section_name = "__General__";
for (sec, prop) in i.iter() {
let section_name = sec.as_ref().unwrap_or(&general_section_name);
println!("-- Section: {:?} begins", section_name);
for (k, v) in prop.iter() {
println!("{}: {:?}", *k, *v);
println!("{}: {:?}", k, v);
}
}
println!();

let section = i.section(Some("User")).unwrap();
println!("name={}", section.get("name").unwrap());
println!("conf[User][name]={}", i["User"]["name"]);
println!("conf[User][name]={}", &i["User"]["name"]);
println!("General Section: {:?}", i.general_section());
}
Loading

0 comments on commit a1a568b

Please sign in to comment.