取消折叠多行函数调用 [英] Uncrustify Collapse Multiline Function Call
问题描述
我有看起来像这样的函数调用(没有明显的原因):
I have function calls that look like this (for no apparent reason):
func
(
a,
b,
c
)
有没有一种方法可以使函数不生锈地将其折叠成一行?我已经尝试了两天了,没有断断续续...
Is there a way to make uncrustify collapse the function into a single line? I have been trying for two days not on and off...
我知道它可以用于函数声明,但是我不能让它用于函数调用.
I got it to work for function declarations, but I don't get it to work for function calls.
在我们遇到的同时,我也有一些看起来像这样的函数:
While we are at it I also have functions that look like so:
func
(
a, // (IN) the A
b, // (IN) something b
c // (OUT) the resulting value
)
有没有办法在不破坏代码的情况下处理这种情况?由于unrustify会保留评论,因此我认为这是不可能的.使用函数声明,它将其折叠到第一个注释.
Is there a way to handle that case too, without breaking the code? Since uncrustify keeps comments, I think this is kind of impossible. With function declarations it collapses it to the first comment.
推荐答案
经过一些深入的研究,我得出了一个结论,那就是,无法进行修饰不能做到这一点.为了我的目的,我一起砍了一个小的perl脚本:
After some LOOONG research I have come to the conclusion, that uncrustify can't do that. For my porposses I hacked a small perl script together:
$filename = $ARGV[0];
{
open(FILE, "<", $filename) or die "Cant open $filename for reading\n";
local $/ = undef;
$lines = <FILE>;
close(FILE);
}
# squash comments in function calls and declarations
$lines =~ s/,[ \t]*\/\/[^\n\r]*/,/gm;
# squash last comment in function calls and declarations
$lines =~ s/[ \t]*\/\/[^\n\r]*\r\n[ \t]*\)/\)/gm;
# squash newlines at the start of a function call or declaration
$lines =~ s/\([ \t]*\r\n[ \t]*/\(/gm;
# squash newlines in function calls and declarations
$lines =~ s/,[ \t]*\r\n[ \t]*/, /gm;
# squash the last newline in a function call or declaration
$lines =~ s/[ \t]*\r\n[ \t]*\)/\)/gm;
{
open(FILE, ">", $filename) or die "Cant open $filename for writing\n";
print FILE $lines;
close(FILE);
}
我会研究是否可以构建将该功能集成到unustify中的补丁.
I will look into if I can build a patch that integrates that feature into uncustify.
这篇关于取消折叠多行函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!