工具括括条件语句 [英] Tools to bracket conditional statement

查看:120
本文介绍了工具括括条件语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道一个工具,可以美化C ++代码添加括号到条件语句?我需要做的是改变:

  if(myCondition)
setDateTime(date,time);

  if(myCondition)
{
setDateTime(date,time);
}

但我必须做这个数百次。我可能在perl写东西,但如果已经有一个工具,但不想走这条路。我使用了 AStyle ,但我找不到如何做到这一点。 / p>

除了满足客户端编码标准,我想要做的是,我必须替换某些调用,如上面的调用 setDateTime (日期,时间) setDate(date) setTime(time)可以很容易地使用正则表达式,但最终像这样:

  if(myCondition)
setDate(date);
setTime(time);

显然不正确!!!

解决方案

static inline void setDateTime(date,time){setDate(date); setTime(time); } : - 添加括号不适用于您,结合 brackets = break ?当我使用astyle,我发现很难让它做我想要的。因此,如果你打算使用它,最简单的方法是定义一组astyle参数的编码风格指南,然后使用astyle来强制它们。



我不会因为不一致的风格,我个人认为这是值得的,但后来客户总是勉强容忍正确。


Does anyone know of a tool which can beautify C++ code to add brackets to conditional statements? 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 could probably write something in perl but don't want to go down this road if there's already a tool. I've used AStyle but I couldn't find how to do this with it.

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:

if ( myCondition )
    setDate( date );
    setTime( time );

Obviously not right!!!

解决方案

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? When I've used astyle, I've found it difficult to get it to do exactly what I want. 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.

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.

这篇关于工具括括条件语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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