[英]Beautify C++ code to add brackets to conditional statements
How can I beautify C++ code to add brackets to conditional statements? 如何美化C ++代码以在条件语句中添加括号? What I need to do is change:
我需要做的是改变:
if ( myCondition )
setDateTime( date, time );
to 至
if ( myCondition )
{
setDateTime( date, time );
}
but I've got to do this hundreds of times. 但我必须这样做几百次。 I've used AStyle but I couldn't find how to do this with it.
我使用过AStyle,但我找不到如何使用它。
Apart from meeting the clients coding standards, the reason I want to do this is that I have to replace certain calls such as the above call to setDateTime( date, time )
with setDate( date )
and setTime( time )
which I can easily enough do with regular expressions but ends up like this: 除了满足客户端编码标准之外,我想要这样做的原因是我必须用
setDate( date )
和setTime( time )
替换某些调用,例如上面调用setDateTime( date, time )
setTime( time )
,我可以很容易使用正则表达式但最终会像这样:
if ( myCondition )
setDate( date );
setTime( time );
Obviously not right!!! 显然不对!
s/setDateTime(date, time)/{ setDate(date); setTime(time); }/
static inline void setDateTime(date, time) { setDate(date); setTime(time); }
Regarding the if
: does the astyle option --add-brackets
not work for you, combined with brackets=break
? 关于
if
:astyle选项--add-brackets
不适合你,结合brackets=break
吗? When I've used astyle, I've found it difficult to get it to do exactly what I want. 当我使用astyle时,我发现很难让它完全符合我的要求。 So if you're going to use it at all, it's easiest to define the coding style guidelines in terms of a set of astyle parameters and then use astyle to enforce them.
因此,如果您要使用它,最简单的方法是根据一组astyle参数定义编码样式指南,然后使用astyle来强制执行它们。
I'm not so bothered by inconsistent style that I personally think that's worth it, but then the customer is always grudgingly tolerated right. 我不会因为我个人认为值得的不一致的风格而烦恼,但客户总是
勉强容忍 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.