change several if statements to match
This commit is contained in:
parent
52c6ed0b64
commit
fc51798595
@ -99,13 +99,11 @@ 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 {
|
||||
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() {
|
||||
@ -121,6 +119,7 @@ impl Value {
|
||||
buf
|
||||
}
|
||||
}
|
||||
}
|
||||
Self::True => "true".to_string(),
|
||||
Self::False => "false".to_string(),
|
||||
Self::Null => "null".to_string(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user