From 219486f0a596fd94cafbd52be0bb93f68e56b76d Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Wed, 13 Jan 2021 10:09:03 +0100 Subject: [PATCH] fmt: cleanup `'` and `"` quotes handling (#8082) --- vlib/v/fmt/fmt.v | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index c63e061096..555fffe716 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1211,21 +1211,17 @@ pub fn (mut f Fmt) expr(node ast.Expr) { } ast.StringInterLiteral { // TODO: this code is very similar to ast.Expr.str() - mut contains_single_quote := false + mut quote := "'" for val in node.vals { if val.contains("'") { - contains_single_quote = true + quote = '"' } if val.contains('"') { - contains_single_quote = false + quote = "'" break } } - if contains_single_quote { - f.write('"') - } else { - f.write("'") - } + f.write(quote) for i, val in node.vals { f.write(val) if i >= node.exprs.len { @@ -1242,11 +1238,7 @@ pub fn (mut f Fmt) expr(node ast.Expr) { f.expr(node.exprs[i]) } } - if contains_single_quote { - f.write('"') - } else { - f.write("'") - } + f.write(quote) } ast.StructInit { f.struct_init(node)