2016-03-03 161 views
-1

我使用go 1.6,我喜欢使用单引号。在完成编辑我的文件后,在我的终端中,我想使用gofmt替换它们,但没有任何效果。如何使用gofmt以双引号替换单引号

gofmt -r "'->\"" book.go 
    parsing pattern ' at 1:1: rune literal not terminated 

我使用zsh。

+1

gofmt不是为了这个,它不能这样做。尝试一些用于此目的的工具,如sed。或者更好:只要在正确的地方编写正确的Go代码即可。单引号有什么特别之处? – Aedolon

回答

3
$ go doc cmd/gofmt 

Gofmt格式Go程序。

的标志是:

-r rule 
    Apply the rewrite rule to the source before reformatting. 

用-r标志指定的重写规则必须 形式的字符串:

pattern -> replacement 

两个模式和替代必须是有效的去表达。在 模式中,单字符小写标识符用作匹配任意子表达式的通配符 ;那些表达式将被 代替替换中的相同标识符。


The Go Programming Language Specification

Expressions

的表达式通过应用 运算符和函数到操作数指定一个值的计算。


两个模式和替代必须是有效的去表达。

相关问题