How can I 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’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-bracketsnot work for you, combined withbrackets=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 toleratedright.