Skip to content

Commit

Permalink
Reformatted
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Apr 2, 2018
1 parent 1d7a8fa commit 4f75342
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ condense_wildcard_suffixes = true
#fn_call_style = "Visual"
#chain_indent = "Visual"
normalize_comments = true
use_try_shorthand = true
use_try_shorthand = true
33 changes: 12 additions & 21 deletions src/ini.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use std::borrow::Borrow;
use std::char;
use std::cmp::Eq;
use std::collections::HashMap;
use std::collections::hash_map::{IntoIter, Iter, IterMut, Keys};
use std::collections::hash_map::Entry;
use std::collections::hash_map::{IntoIter, Iter, IterMut, Keys};
use std::error;
use std::fmt::{self, Display};
use std::fs::{File, OpenOptions};
Expand Down Expand Up @@ -444,21 +444,19 @@ impl Ini {
/// Load from a reader
pub fn read_from<R: Read>(reader: &mut R) -> Result<Ini, Error> {
let mut s = String::new();
reader.read_to_string(&mut s)
.map_err(|err| Error { line: 0,
col: 0,
msg: format!("{}", err), })?;
reader.read_to_string(&mut s).map_err(|err| Error { line: 0,
col: 0,
msg: format!("{}", err), })?;
let mut parser = Parser::new(s.chars(), false);
parser.parse()
}

/// Load from a reader, but do not interpret '\' as an escape character
pub fn read_from_noescape<R: Read>(reader: &mut R) -> Result<Ini, Error> {
let mut s = String::new();
reader.read_to_string(&mut s)
.map_err(|err| Error { line: 0,
col: 0,
msg: format!("{}", err), })?;
reader.read_to_string(&mut s).map_err(|err| Error { line: 0,
col: 0,
msg: format!("{}", err), })?;
let mut parser = Parser::new(s.chars(), true);
parser.parse()
}
Expand Down Expand Up @@ -680,9 +678,7 @@ impl<'a> Parser<'a> {
Ok(sec) => {
let msec = &sec[..].trim();
cursec = Some(msec.to_string());
result.sections
.entry(cursec.clone())
.or_insert(HashMap::new());
result.sections.entry(cursec.clone()).or_insert(HashMap::new());
self.bump();
}
Err(e) => return Err(e),
Expand All @@ -695,9 +691,7 @@ impl<'a> Parser<'a> {
match self.parse_val() {
Ok(val) => {
let mval = val[..].trim().to_owned();
let sec = result.sections
.entry(cursec.clone())
.or_insert(HashMap::new());
let sec = result.sections.entry(cursec.clone()).or_insert(HashMap::new());
sec.insert(curkey, mval);
curkey = "".into();
}
Expand Down Expand Up @@ -915,8 +909,7 @@ gender : mail ; abdddd
";
let ini = Ini::load_from_str(input).unwrap();
assert_eq!(ini.get_from(Some("section name"), "name").unwrap(), "hello");
assert_eq!(ini.get_from(Some("section name"), "gender").unwrap(),
"mail");
assert_eq!(ini.get_from(Some("section name"), "gender").unwrap(), "mail");
}

#[test]
Expand All @@ -939,8 +932,7 @@ Key = \"Value
Otherline\"
";
let ini = Ini::load_from_str(input).unwrap();
assert_eq!(ini.get_from(Some("section name"), "Key").unwrap(),
"Value\nOtherline");
assert_eq!(ini.get_from(Some("section name"), "Key").unwrap(), "Value\nOtherline");
}

#[test]
Expand Down Expand Up @@ -990,8 +982,7 @@ Otherline'
Stuff = Other
";
let ini = Ini::load_from_str(input).unwrap();
assert_eq!(ini.get_from(Some("section name"), "Key").unwrap(),
"Value\nOtherline");
assert_eq!(ini.get_from(Some("section name"), "Key").unwrap(), "Value\nOtherline");
}

#[test]
Expand Down

0 comments on commit 4f75342

Please sign in to comment.