From f6497ca3fbec4474084b8d13b39bd1bd1a87208d Mon Sep 17 00:00:00 2001 From: "Victor M. Suarez" Date: Sat, 2 Jan 2016 20:47:10 -0500 Subject: [PATCH] ignore case for config enums. Fixes #738 --- src/utils.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index a13ca2479649..83018a25ebb7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -198,13 +198,14 @@ macro_rules! impl_enum_decodable { ( $e:ident, $( $x:ident ),* ) => { impl ::rustc_serialize::Decodable for $e { fn decode(d: &mut D) -> Result { + use std::ascii::AsciiExt; let s = try!(d.read_str()); - match &*s { - $( - stringify!($x) => Ok($e::$x), - )* - _ => Err(d.error("Bad variant")), - } + $( + if stringify!($x).eq_ignore_ascii_case(&s) { + return Ok($e::$x); + } + )* + Err(d.error("Bad variant")) } } @@ -212,12 +213,13 @@ macro_rules! impl_enum_decodable { type Err = &'static str; fn from_str(s: &str) -> Result { - match &*s { - $( - stringify!($x) => Ok($e::$x), - )* - _ => Err("Bad variant"), - } + use std::ascii::AsciiExt; + $( + if stringify!($x).eq_ignore_ascii_case(s) { + return Ok($e::$x); + } + )* + Err("Bad variant") } }