change several if statements to match
This commit is contained in:
parent
52c6ed0b64
commit
fc51798595
@ -99,26 +99,25 @@ 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)
|
let mut buf = String::with_capacity(val.len() + 2);
|
||||||
} else {
|
buf.push('"');
|
||||||
let mut buf = String::with_capacity(val.len() + 2);
|
for c in val.chars() {
|
||||||
buf.push('"');
|
match c {
|
||||||
for c in val.chars() {
|
'"' => {
|
||||||
match c {
|
buf.push('\\');
|
||||||
'"' => {
|
buf.push('"');
|
||||||
buf.push('\\');
|
}
|
||||||
buf.push('"');
|
v => buf.push(v),
|
||||||
}
|
}
|
||||||
v => buf.push(v),
|
|
||||||
}
|
}
|
||||||
|
buf.push('"');
|
||||||
|
buf
|
||||||
}
|
}
|
||||||
buf.push('"');
|
|
||||||
buf
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self::True => "true".to_string(),
|
Self::True => "true".to_string(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user