c – 应该使用什么选项来使用astyle删除多余的空格?

如何使用astyle从代码中删除多余的空格?例如,我想转换以下代码:

void foo (     int  a  ,  int   c )
{
d   = a+      c;
}

对此:

void foo (int a, int c)
{
    d = a + c;
}

但是astyle目前正在将其转换为:

void foo (int  a  ,  int   c)
{
    d   = a +      c;
}

最佳答案 目前没有办法在astyle中打开操作符周围的空间.如果有办法取消运算符的操作,

您可以首先取消填充空格,然后再使用-p选项填充它们.

–pad-oper / -p

Insert space padding around operators.

Any end of line comments will remain in the original column, if possible.

Note that there is no option to unpad. Once padded, they stay padded.

if (foo==2)
    a=bar((b-c)*a,d--);

becomes:

if (foo == 2)
    a = bar((b - c) * a, d--);

资料来源:http://astyle.sourceforge.net/astyle.html#_pad-oper

点赞