【问题标题】:clang format break before double colon双冒号前的clang格式中断
【发布时间】:2020-04-05 08:25:04
【问题描述】:

我目前正在代码库上逐步应用 clang 格式,并提出了一个场景,它给出的结果不是我们真正想要的结果,因为 :: 的换行位置采取以下示例。

// Manual format was.
bool
foo::MyLongClassName::MyLongFunctionName(
  const Type1& Argument1,
  const Type2& Argument2);

// After clang format.
bool foo::MyLongClassName::
  MyLongFunctionName(const Type1& Argument1,
                     const Type2& Argument2);

我的同事有评论:

我总是喜欢将函数名放在双冒号旁边,因为这样可以很容易地搜索方法实现。

有没有办法获得 clang 格式来更改换行符发生的一侧?

例如所以它输出如下:

// After clang format.
bool foo::MyLongClassName
::MyLongFunctionName(const Type1& Argument1,
                     const Type2& Argument2);

【问题讨论】:

  • 你可以找到各种选项here
  • 是的,我一直在使用它作为参考,但没有找到改变布局行为的方法。
  • 您的预期输出是什么。您能否在您的问题中提及该代码
  • 我已经更新到最后添加了一个示例。

标签: c++ namespaces format clang-format


【解决方案1】:

目前,我的工作是应用 post clang 格式 hack 来手动移动双冒号,遍历文件的行并运行 perl 正则表达式。

  # Hack - fix breaking after scoping operator, instead we want the
  # break to be before the scoping operator so we move it down a line.
  if ($line =~ /^.+::$/ &&
      $lines[$lineNo + 1] =~ /^  [A-Z].+$/)
  {
    $line = substr($line, 0, -2);
    $lines[$lineNo + 1] = "::".substr($lines[$lineNo + 1], 2);
  }

【讨论】:

    猜你喜欢
    • 2021-05-11
    • 2014-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    • 2019-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多