當前位置:編程學習大全網 - 源碼下載 - 如何在source insight中使用astyle的代碼整理功能

如何在source insight中使用astyle的代碼整理功能

用source insight 編輯代碼時,苦於source insight沒有集成的代碼格式化工具, GNU的astyle是壹個免費的代碼格式化工具,能夠整理符合c/c++規範。

我們可以將astyle.exe外掛到SourceInsight中。詳細步驟如下:

1:從es:

switch (foo)

{

case 1:

a += 1;

break;

case 2:

{

a += 2;

break;

}

}

--indent-preprocessor / -w

用“/”對齊多行參數

#define Is_Bar(arg,a,b) /

(Is_Foo((arg), (a)) /

|| Is_Foo((arg), (b)))

becomes:

#define Is_Bar(arg,a,b) /

(Is_Foo((arg), (a)) /

|| Is_Foo((arg), (b)))

--break-blocks / -f

在關鍵字if, for, while與()之間填充空格,在不相關代碼之間加上空行

isFoo = true;

if (isFoo) {

bar();

} else {

anotherBar();

}

isBar = false;

becomes:

isFoo = true;

if (isFoo) {

bar();

} else {

anotherBar();

}

isBar = false;

--pad-oper / -p

在各雙目運算符的前後分別加上空格,行末會保持原樣。

if (foo==2)

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

becomes:

if (foo == 2)

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

--delete-empty-lines / -x

刪除函數裏邊的空行。函數外面的空行不會被刪除。

void Foo()

{

foo1 = 1;

foo2 = 2;

}

becomes:

void Foo()

{

foo1 = 1;

foo2 = 2;

}

--pad-header / -H

在關鍵字 ‘if’,‘for’, ‘while’..與括號之間填充空格。任何行註釋的末尾都會保留原始列。

if(isFoo(a, b))

bar(a, b);

becomes:

if (isFoo(a, b))

bar(a, b);

--unpad-paren / -U

移除括號裏邊和外邊的的無用空間

if ( isFoo( a, b ) )

bar ( a, b );

becomes (with no padding option requested):

if(isFoo(a, b))

bar(a, b);

--add-one-line-brackets / -J

為 ‘if’, ‘for’, ‘while’裏的單行語句加上{}。這條語句只能和{}在同壹行。如果相變成不同行,需要手動修改。

if (isFoo)

isFoo = false;

becomes:

if (isFoo)

{ isFoo = false; }

--align-pointer=type / -k1

--align-pointer=middle / -k2

--align-pointer=name / -k3

對齊指針,引用(* or &)的標號位置,使其位於變量類型壹側或變量名壹側,也可以處在類型與名稱之間。

char *foo1;

becomes (with align-pointer=type):

char* foo1;

char* foo2;

becomes (with align-pointer=middle):

char * foo2;

char & foo3;

becomes (with align-pointer=name):

char &foo3;

--suffix=none / -n

不保留文件的備份文件。文件在格式化之後,原始文件會清除

  • 上一篇:軟件外包開發流程和報價是多少
  • 下一篇:HAVOK引擎是哪個國家做的?
  • copyright 2024編程學習大全網