AStyle version: 1.23
and the arguments is:
--style=allman --indent=spaces --indent-cases --indent-preprocessor --pad-oper --unpad-paren --keep-one-line-statements --keep-one-line-blocks --convert-tabs --suffix=none
If use this arguments, it's can be format this code FROM:
int main()
{
for(int i=0;i<10;++i)
{
cout << i << endl;
}
return 0;
}
TO:
int main()
{
for (int i = 0; i < 10; ++i)
{
cout << i << endl;
}
return 0;
}
NOTICE:
for{HERE is a space}(int i = 0; i < 10; ++i)
But, if i setting AStyle Plugin like below picture show, it's only format the code TO:
int main()
{
for(int i = 0; i < 10; ++i)
{
cout << i << endl;
}
return 0;
}
IN for and (, NOT space in there.
[attachment deleted by admin]
Still have problems, if this option is enabled, the following code to have a problem.
#include <windows.h>
int main()
{
for (int i = 0; i < 10; ++i)
{
cout << i << endl;
}
::MessageBox (0, 0, 0, 0);
return 0;
}
::MessageBox(0, 0, 0, 0);
formated to ::MessageBox (0, 0, 0, 0);
example, this code:
#include <windows.h>
int Foo (bool isBar)
{
if ( isBar () )
{
bar ();
return 1;
}
else
return 0;
}
int main()
{
for (int i = 0; i < 10; ++i)
{
cout << i << endl;
}
::MessageBox (0, 0, 0, 0);
return 0;
}
How to format it to:
#include <windows.h>
int Foo(bool isBar)
{
if (isBar())
{
bar();
return 1;
}
else
return 0;
}
int main()
{
for (int i = 0; i < 10; ++i)
{
cout << i << endl;
}
::MessageBox(0, 0, 0, 0);
return 0;
}
but not:
#include <windows.h>
int Foo(bool isBar)
{
if(isBar())
{
bar();
return 1;
}
else
return 0;
}
int main()
{
for(int i = 0; i < 10; ++i)
{
cout << i << endl;
}
::MessageBox(0, 0, 0, 0);
return 0;
}
[attachment deleted by admin]
example, this code:
[...]
How to format it to:
[...]
but not:
[...]
That's simply not possible with the set of options given.
Do not, AStyle can do that!
Launching tool 'AStyle': D:\LoveDEV\tool\AStyle.exe --style=allman --indent=spaces --indent-cases --indent-preprocessor --pad-oper --unpad-paren --keep-one-line-statements --keep-one-line-blocks --convert-tabs --suffix=none D:\Projects\fsefe\main.cpp (in D:\Projects\fsefe)
stdout> formatted D:\Projects\fsefe\main.cpp
Tool execution terminated with status 0
Current code:
#include <windows.h>
int Foo(bool isBar)
{
if( isBar ( ) )
{
bar ( );
return 1;
}
else
return 0;
}
int main()
{
for(int i = 0; i < 10; ++i)
{
cout << i << endl;
}
::MessageBox (0, 0, 0, 0);
return 0;
}
Can formatted to :
#include <windows.h>
int Foo(bool isBar)
{
if (isBar())
{
bar();
return 1;
}
else
return 0;
}
int main()
{
for (int i = 0; i < 10; ++i)
{
cout << i << endl;
}
::MessageBox(0, 0, 0, 0);
return 0;
}
[attachment deleted by admin]
As another example, thic code:
void test() {}
void func(int i) {}
int main()
{
test();
func(1);
if(int i=0;i<10;++i) test();
return 0;
}
if use run Astyle plugin, it's became to:
void test() {}
void func (int i) {}
int main()
{
test();
func (1);
if (int i = 0; i < 10; ++i) test();
return 0;
}
Notice:
AStyle 1.24 release, I think the reason is:
--pad-header / -H
Insert space padding after paren headers only (e.g. 'if', 'for', 'while'...). Any end of line comments will remain in the original column, if possible. This can be used with unpad-paren to remove unwanted spaces.
if(isFoo(a, b))
bar(a, b);
becomes:
if (isFoo(a, b))
bar(a, b);
http://astyle.sourceforge.net/astyle.html (http://astyle.sourceforge.net/astyle.html)
And the : --pad-header will fix this problem. :lol: