What option should be used to remove extra spaces using astyle?
Asked Answered
F

3

8

How can I remove extra spaces from my code using astyle? For example I want to convert the following code:

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

to this:

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

But astyle is currently converting it to this:

void foo (int  a  ,  int   c)
{
    d   = a +      c;
}
Furry answered 6/6, 2015 at 7:47 Comment(0)
S
2

--squeeze-ws can do this job finally (astyle v3.3+)

https://astyle.sourceforge.net/astyle.html#_squeeze-ws

Sixfold answered 7/7, 2023 at 2:7 Comment(0)
E
3

There is currently no way to unpad the spaces around operators in astyle. If there had been a way to unpad the operators, you could have first unpadded the spaces, and then again pad them using -p option.

--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--);

Source : http://astyle.sourceforge.net/astyle.html#_pad-oper

Eads answered 6/6, 2015 at 8:50 Comment(0)
S
2

--squeeze-ws can do this job finally (astyle v3.3+)

https://astyle.sourceforge.net/astyle.html#_squeeze-ws

Sixfold answered 7/7, 2023 at 2:7 Comment(0)
I
0

You can use --pad-header / -H to unpad.

Reference:http://astyle.sourceforge.net/astyle.html#_unpad-paren

Indoeuropean answered 25/9, 2020 at 4:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.