From a40a2cb389b97844e3ebd615f53273be0c004edd Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 30 May 2017 23:31:32 +0100 Subject: Store fraction of seconds in times unconditionally This way, times without fractional seconds will be compare equal to times with 0 fractional seconds if all else is equal. For example, 06:00:00 == 06:00:00.0 Closes https://github.com/alexcrichton/toml-rs/issues/179 --- src/datetime.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/datetime.rs b/src/datetime.rs index 7917cad..f39d9fa 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -55,7 +55,7 @@ struct Time { hour: u8, minute: u8, second: u8, - secfract: Option, + secfract: f64, } #[derive(PartialEq, Clone)] @@ -97,8 +97,8 @@ impl fmt::Display for Date { impl fmt::Display for Time { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:02}:{:02}:{:02}", self.hour, self.minute, self.second)?; - if let Some(i) = self.secfract { - let s = format!("{}", i); + if self.secfract != 0.0 { + let s = format!("{}", self.secfract); write!(f, "{}", s.trim_left_matches("0"))?; } Ok(()) @@ -219,11 +219,11 @@ impl FromStr for Datetime { } chars = whole[end..].chars(); match format!("0.{}", &whole[..end]).parse() { - Ok(f) => Some(f), + Ok(f) => f, Err(_) => return Err(DatetimeParseError { _private: () }), } } else { - None + 0.0 }; let time = Time { -- cgit v1.2.3 From f98d6ccd70850708ca9d7fc98c561556148b397d Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 30 May 2017 23:49:26 +0100 Subject: Encode control characters with hex not decimal Fix https://github.com/alexcrichton/toml-rs/issues/178 --- src/ser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ser.rs b/src/ser.rs index 9af304f..de5d41c 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -290,7 +290,7 @@ impl<'a> Serializer<'a> { '\u{22}' => drop(write!(self.dst, "\\\"")), '\u{5c}' => drop(write!(self.dst, "\\\\")), c if c < '\u{1f}' => { - drop(write!(self.dst, "\\u{:04}", ch as u32)) + drop(write!(self.dst, "\\u{:04X}", ch as u32)) } ch => drop(write!(self.dst, "{}", ch)), } -- cgit v1.2.3