用clang格式,处罚是怎么做的? [英] In clang-format, what do the penalties do?

查看:109
本文介绍了用clang格式,处罚是怎么做的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

clang格式的sytle选项文档包括许多称为PenaltyXXX的选项.该文档没有说明应如何使用这些罚款.您能否描述这些惩罚值的使用方法以及它们所能达到的效果(也许举一个例子)?

The clang-format sytle options documentation includes a number of options called PenaltyXXX. The documentation doesn't explain how these penalties should be used. Can you describe how to use these penalty values and what effect they achieve (perhaps with an example)?

推荐答案

当您的行超出了行长限制时,clang格式将需要在某处插入一个或多个中断.您可以将处罚视为阻止某些断行行为的一种方式.例如,假设您有:

When you have a line that's over the line length limit, clang-format will need to insert one or more breaks somewhere. You can think of penalties as a way of discouraging certain line-breaking behavior. For instance, say you have:

Namespaces::Are::Pervasive::SomeReallyVerySuperDuperLongFunctionName(args);
// and the column limit is here:                                        ^

Clang格式可能会显得有些奇怪:

Clang-format will probably format to look a little strange:

Namespaces::Are::Pervasive::SomeReallyVerySuperDuperLongFunctionName(
    args);

在这种情况下,您可能会决定您愿意以一两个字符违反行长,因此您可以通过将 PenaltyExcessCharacter 设置为较小的数字并PenaltyBreakBeforeFirstCallParameter 设置为更高的数字.

You might decide that you're willing to violate the line length by a character or two for cases like this, so you could steer that by setting the PenaltyExcessCharacter to a low number and PenaltyBreakBeforeFirstCallParameter to a higher number.

就个人而言,当返回类型单独显示时,我真的很不喜欢,所以我将 PenaltyReturnTypeOnItsOwnLine 设置为一个非常大的数字.

Personally, I really dislike when the return type is on its own line, so I set PenaltyReturnTypeOnItsOwnLine to an absurdly large number.

此外,该系统是从Latex继承的,它使您可以指定换行,分页和断字的各种惩罚.

An aside, this system was inherited from Latex, which allows you to specify all kinds of penalties for line-breaking, pagination, and hyphenation.

这篇关于用clang格式,处罚是怎么做的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆