fmt: cleanup `'` and `"` quotes handling (#8082)
parent
a22982d662
commit
219486f0a5
|
@ -1211,21 +1211,17 @@ pub fn (mut f Fmt) expr(node ast.Expr) {
|
||||||
}
|
}
|
||||||
ast.StringInterLiteral {
|
ast.StringInterLiteral {
|
||||||
// TODO: this code is very similar to ast.Expr.str()
|
// TODO: this code is very similar to ast.Expr.str()
|
||||||
mut contains_single_quote := false
|
mut quote := "'"
|
||||||
for val in node.vals {
|
for val in node.vals {
|
||||||
if val.contains("'") {
|
if val.contains("'") {
|
||||||
contains_single_quote = true
|
quote = '"'
|
||||||
}
|
}
|
||||||
if val.contains('"') {
|
if val.contains('"') {
|
||||||
contains_single_quote = false
|
quote = "'"
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if contains_single_quote {
|
f.write(quote)
|
||||||
f.write('"')
|
|
||||||
} else {
|
|
||||||
f.write("'")
|
|
||||||
}
|
|
||||||
for i, val in node.vals {
|
for i, val in node.vals {
|
||||||
f.write(val)
|
f.write(val)
|
||||||
if i >= node.exprs.len {
|
if i >= node.exprs.len {
|
||||||
|
@ -1242,11 +1238,7 @@ pub fn (mut f Fmt) expr(node ast.Expr) {
|
||||||
f.expr(node.exprs[i])
|
f.expr(node.exprs[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if contains_single_quote {
|
f.write(quote)
|
||||||
f.write('"')
|
|
||||||
} else {
|
|
||||||
f.write("'")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ast.StructInit {
|
ast.StructInit {
|
||||||
f.struct_init(node)
|
f.struct_init(node)
|
||||||
|
|
Loading…
Reference in New Issue