【问题标题】:Adding braces for If-else using Uncrustify使用 Uncrustify 为 If-else 添加大括号
【发布时间】:2013-12-18 10:24:50
【问题描述】:

我想知道是否有任何方法可以使用 Uncrustify 在嵌套的 If-else 中添加大括号。例如:

if( stat_error == -1 ){
   if ( debug > 0 )
      printf( "...ERROR ); //I would like to add braces around here.
   exit( -1 );
} else {

我看过这个:

# Add or remove braces on single-line 'if' statement. Will not remove the braces if they contain an 'else'.
mod_full_brace_if                        = add   # ignore/add/remove/force

但它似乎不适用于嵌套条件。

有什么办法吗?

【问题讨论】:

    标签: if-statement uncrustify


    【解决方案1】:

    我在您的示例中使用 Uncrustify 的经验:

    在单行if 语句中添加或删除大括号。如果大括号包含else,则不会删除它们。

    mod_full_brace_if = add
    

    使链中的所有 if / elseif / else 语句都被支撑或不支撑。覆盖mod_full_brace_if

    如果任何必须支撑,它们都被支撑。如果所有都可以解开,则移除大括号。

    mod_full_brace_if_chain = false
    

    它对我有用。

    【讨论】:

      【解决方案2】:

      你需要添加一个return语句应该是这样的

          if( stat_error == -1 ){
         if ( debug > 0 )
            printf( "...ERROR ); //I would like to add braces around here.
         exit( -1 );
      } else{
      
      Insert else statement
      }
      return statement here
      }
      

      【讨论】:

      • 我不明白。我为什么要添加它?
      • 这个答案与提出的问题完全无关。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-11
      • 2013-06-14
      • 2021-03-15
      • 2019-01-08
      相关资源
      最近更新 更多