最佳 C++ 代码格式化程序/美化程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/841075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best C++ Code Formatter/Beautifier
提问by Kristopher Johnson
There are lots of source code formatting tools out there. Which ones work best for C++?
有很多源代码格式化工具。哪些最适合 C++?
I'm interested in command-line tools or other things that can be automatically run when checking code in/out, preferably without needing to launch an editor or IDE.
我对命令行工具或其他可以在签入/签出代码时自动运行的东西感兴趣,最好不需要启动编辑器或 IDE。
(If you see the one you like already listed as an answer, vote it up. If it's not there, add it.)
(如果您看到您喜欢的已作为答案列出,请投票。如果不存在,请添加。)
采纳答案by John Weldon
AStylecan be customized in great detail for C++ and Java (and others too)
AStyle可以为 C++ 和 Java(以及其他)进行非常详细的定制
This is a source code formatting tool.
这是一个源代码格式化工具。
clang-formatis a powerful command linetool bundled with the clang compiler which handles even the most obscure language constructs in a coherent way.
clang-format是一个强大的命令行工具,与 clang 编译器捆绑在一起,它以连贯的方式处理最晦涩的语言结构。
It can be integrated with Visual Studio, Emacs, Vim (and others) and can format just the selected lines (or with git/svn to format some diff).
它可以与 Visual Studio、Emacs、Vim(和其他)集成,并且可以只格式化选定的行(或使用 git/svn 来格式化一些差异)。
It can be configured with a variety of options listed here.
可以使用此处列出的各种选项对其进行配置。
When using config files (named .clang-format
) styles can be per directory - the closest such file in parent directories shall be used for a particular file.
使用配置文件(命名.clang-format
)时,样式可以是每个目录 - 父目录中最接近的此类文件应用于特定文件。
Styles can be inherited from a preset (say LLVM or Google) and can later override different options
样式可以从预设(比如 LLVM 或 Google)继承,以后可以覆盖不同的选项
It is used by Google and others and is production ready.
它已被 Google 和其他公司使用,并已准备好投入生产。
Also look at the project UniversalIndentGUI. You can experiment with several indenters using it: AStyle, Uncrustify, GreatCode, ... and select the best for you. Any of them can be run later from a command line.
另请查看UniversalIndentGUI项目。您可以使用它尝试多种压头:AStyle、Uncrustify、GreatCode ……并选择最适合您的。它们中的任何一个都可以稍后从命令行运行。
Uncrustifyhas a lotof configurable options. You'll probably need Universal Indent GUI (in Konstantin's reply) as well to configure it.
Uncrustify有很多可配置的选项。您可能还需要 Universal Indent GUI(在 Konstantin 的回复中)来配置它。