gpt4 book ai didi

c++ - 如何使用 clang-format 在 switch 中获取单行对齐的 case 语句

转载 作者:可可西里 更新时间:2023-11-01 15:22:19 28 4
gpt4 key购买 nike

我想要clang-format格式如下:

switch (x)
{
case long_name: return 1;
case sn: return 2;
}

AllowShortCaseLabelsOnASingleLine 选项让它们在同一行,
但我还没有找到让语句对齐的方法。

最佳答案

截至目前,使用 ClangFormat 无法完成您要求的操作。

官方的解释是:

Each additional style option adds costs to the clang-format project. Some of these costs affect the clang-format development itself, as we need to make sure that any given combination of options work and that new features don’t break any of the existing options in any way. There are also costs for end users as options become less discoverable and people have to think about and make a decision on options they don’t really care about.

The goal of the clang-format project is more on the side of supporting a limited set of styles really well as opposed to supporting every single style used by a codebase somewhere in the wild. [...]

你可能能够做这样的事情的唯一方法是:

  1. 向开发人员建议样式选项;
  2. 等待添加所需的样式选项;
  3. 使用能够对齐语句的 ClangFormat 替代方法。

来源:

  1. https://clang.llvm.org/docs/ClangFormatStyleOptions.html#configurable-format-style-options
  2. https://clang.llvm.org/docs/ClangFormatStyleOptions.html#adding-additional-style-options

关于c++ - 如何使用 clang-format 在 switch 中获取单行对齐的 case 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44540197/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com