2016-01-27 47 views
5

我想知道是否可以設置clang格式以將非compound_statement減少爲iteration_statement中的{ non-compound_statement; }clang-format if()while()for()if()while()for()

statement 
: labeled_statement 
| compound_statement 
| expression_statement 
| selection_statement 
| iteration_statement 
| jump_statement 
; 
iteration_statement 
: WHILE '(' expression ')' statement 
| DO statement WHILE '(' expression ')' ';' 
| FOR '(' expression_statement expression_statement ')' statement 
| FOR '(' expression_statement expression_statement expression ')' statement 
; 

輸入:

if (exp) foo = 1; 

輸出:

if (exp) { foo = 1; } 

然後將凹痕作爲所需的美化。

+0

鐺格式可能不是你要找的內容。你有沒有嘗試過使用'clang-tidy'? – PythonJin

回答

1

你想要做的是什麼鐺格式的範圍之外試圖達到:

  • 唯一的詞彙元素鐺格式應該接觸是:空格,字符串和註釋。任何其他變化 不等,從排序包括到刪除多餘的要素 都不在此工具的範圍之內。

來源:http://clang-developers.42468.n3.nabble.com/Design-clang-format-td3980439.html

然而鏗鏘整齊即可,功能標誌被稱爲readability-braces-around-statements

來源:http://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html