From fc51798595ebb651a4e0b4071fb12ff5d31964e3 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sat, 18 Apr 2020 13:22:06 -0400 Subject: [PATCH] change several if statements to match --- src/value/mod.rs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/value/mod.rs b/src/value/mod.rs index f9e1ab7..528ea26 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -99,26 +99,25 @@ impl Value { Self::Ident(val, QuoteKind::Quoted) => { let has_single_quotes = val.contains(|x| x == '\''); let has_double_quotes = val.contains(|x| x == '"'); - if has_single_quotes && !has_double_quotes { - format!("\"{}\"", val) - } else if !has_single_quotes && has_double_quotes { - format!("'{}'", val) - } else if !has_single_quotes && !has_double_quotes { - format!("\"{}\"", val) - } else { - let mut buf = String::with_capacity(val.len() + 2); - buf.push('"'); - for c in val.chars() { - match c { - '"' => { - buf.push('\\'); - buf.push('"'); + match (has_single_quotes, has_double_quotes) { + (true, false) => format!("\"{}\"", val), + (false, true) => format!("'{}'", val), + (false, false) => format!("\"{}\"", val), + (true, true) => { + let mut buf = String::with_capacity(val.len() + 2); + buf.push('"'); + for c in val.chars() { + match c { + '"' => { + buf.push('\\'); + buf.push('"'); + } + v => buf.push(v), } - v => buf.push(v), } + buf.push('"'); + buf } - buf.push('"'); - buf } } Self::True => "true".to_string(),