From 3afa6061544bd197ba3e615128823a81435a783b Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Sun, 29 Nov 2020 14:09:50 +0530 Subject: [PATCH] vfmt: fix eating `c` in `c'foo'` (#7009) * fmt: add formatting for cstrs * fmt --- vlib/v/fmt/fmt.v | 2 ++ vlib/v/fmt/tests/string_raw_and_cstr_keep.vv | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 vlib/v/fmt/tests/string_raw_and_cstr_keep.vv diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 42dce6ef57..bc9fd3c3ee 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1031,6 +1031,8 @@ pub fn (mut f Fmt) expr(node ast.Expr) { ast.StringLiteral { if node.is_raw { f.write('r') + } else if node.language == table.Language.c { + f.write('c') } if node.val.contains("'") && !node.val.contains('"') { f.write('"$node.val"') diff --git a/vlib/v/fmt/tests/string_raw_and_cstr_keep.vv b/vlib/v/fmt/tests/string_raw_and_cstr_keep.vv new file mode 100644 index 0000000000..89e3010e82 --- /dev/null +++ b/vlib/v/fmt/tests/string_raw_and_cstr_keep.vv @@ -0,0 +1,6 @@ +fn main() { + raw := r'\x00' + cstr := c'foo' + println(raw) + println(cstr) +}