首页 > 解决方案 > 在 if、for、while 语句之前和之后添加换行符,使用 clang 格式(Astyle 等效 --break-blocks)

问题描述

我一直在使用clang-formatLinux Kernel 存储库中可用的样式,我想根据自己的需要对其进行调整。我试图在 if、for 和 while 块之前和之后添加换行符。

虽然我从未使用过 Astyle,但它通过--break-blocks 标志实现了所需的行为

Astyle 文档中的一个示例

isFoo = true;
if (isFoo) {
    bar();
} else {
    anotherBar();
}
isBar = false;

变成:

isFoo = true;

if (isFoo) {
    bar();
} else {
    anotherBar();
}

isBar = false;

我搜索了 的文档,clang-format但找不到可以实现相同样式的标志。

有没有办法使用 实现这种风格clang-format

标签: c++cllvmclang-format

解决方案


推荐阅读