我想知道是否可以使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并使用后clang格式的hack来使用perl regex将空捕获更改为单行:
# 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";
}