我想知道是否有可能让 clang 格式具有以下异常处理格式。
// Scenario 1: Catch and ignore exception
try
{
DoWork();
}
catch (const SomeException&) {}
// Scenario 2: Handle exception
try
{
DoWork();
}
catch (const SomeException& Exception)
{
// Code handling exception.
}
我无法在单行上获得场景 1 格式,它更喜欢在 { 之前放置一个新行,然后取决于 SplitEmptyFunction 将是:
// Scenario 1: Catch and ignore exception (SplitEmptyFunction is true)
try
{
DoWork();
}
catch (const SomeException&)
{}
// Scenario 1: Catch and ignore exception (SplitEmptyFunction is false)
try
{
DoWork();
}
catch (const SomeException&)
{
}
我是否错过了设置,或者这是不可能的?
目前我的工作是将 SplitEmptyFunction 保持为 false 并应用 post clang 格式 hack 以使用 perl 正则表达式将空捕获更改为在一行上:
# Hack - allow empty catch statements on a single line.
if ($line =~ /^.+catch.+$/ &&
$lines[$lineNo + 1] =~ /^ +\{ *$/ &&
$lines[$lineNo + 2] =~ /^ +\} *$/)
{
$line = $line." {}";
# Flag following lines when iterated over to be ignored.
$lines[$lineNo + 1] = "clang_format_no_op_entire_statement";
$lines[$lineNo + 2] = "clang_format_no_op_entire_statement";
}
我是一名优秀的程序员,十分优秀!