change several if statements to match

This commit is contained in:
ConnorSkees 2020-04-18 13:22:06 -04:00
parent 52c6ed0b64
commit fc51798595

View File

@ -99,13 +99,11 @@ impl Value {
Self::Ident(val, QuoteKind::Quoted) => { Self::Ident(val, QuoteKind::Quoted) => {
let has_single_quotes = val.contains(|x| x == '\''); let has_single_quotes = val.contains(|x| x == '\'');
let has_double_quotes = val.contains(|x| x == '"'); let has_double_quotes = val.contains(|x| x == '"');
if has_single_quotes && !has_double_quotes { match (has_single_quotes, has_double_quotes) {
format!("\"{}\"", val) (true, false) => format!("\"{}\"", val),
} else if !has_single_quotes && has_double_quotes { (false, true) => format!("'{}'", val),
format!("'{}'", val) (false, false) => format!("\"{}\"", val),
} else if !has_single_quotes && !has_double_quotes { (true, true) => {
format!("\"{}\"", val)
} else {
let mut buf = String::with_capacity(val.len() + 2); let mut buf = String::with_capacity(val.len() + 2);
buf.push('"'); buf.push('"');
for c in val.chars() { for c in val.chars() {
@ -121,6 +119,7 @@ impl Value {
buf buf
} }
} }
}
Self::True => "true".to_string(), Self::True => "true".to_string(),
Self::False => "false".to_string(), Self::False => "false".to_string(),
Self::Null => "null".to_string(), Self::Null => "null".to_string(),