fmt: cleanup `'` and `"` quotes handling (#8082)

pull/8122/head
Lukas Neubert 2021-01-13 10:09:03 +01:00 committed by GitHub
parent a22982d662
commit 219486f0a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 13 deletions

View File

@ -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)