Reputation: 31
I'm currently applying clang formatting incrementally over a code base and came up with a scenario where it is giving a result that is not what we really want with the line breaking location of :: take the following example.
// 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);
My co-worker had the review comment:
I always prefer to keep the function name next to the double colon, as it makes searching for a method implementation easy.
Is there a way to get clang format to change the side the line break occurs on?
E.g. so it outputs instead like:
// After clang format.
bool foo::MyLongClassName
::MyLongFunctionName(const Type1& Argument1,
const Type2& Argument2);
Upvotes: 0
Views: 254
Reputation: 31
For now my work around has been to apply a post clang format hack to move the double colon manually with iterating over the lines of the file and running a perl regex.
# 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);
}
Upvotes: 0