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,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(),