我开始使用Allman风格进行编码,使用对齐的大括号:
void foobar() { if(foo) { bar(); } }几十年后,我决定要增加屏幕空间; 此外,我的客户使用不匹配的大括号,因此很难从工作中来回切换到我的个人代码。 所以我想将现有的所有代码转换为K&R:
void foobar() { if(foo) { bar(); } }Eclipse 4.4有足够的代码格式化程序,如果我选择源代码树,我甚至可以批量格式化文件。 问题是,如果我有一个K&R括号的行注释,Eclipse会拒绝将一个支架移动到一条线上,让我有一个大杂烩的编码风格:
void foobar() { if(foo) //if foo { bar(); } }我怎么能告诉Eclipse移动支架,即使支架上的线有注释?
void foobar() { if(foo) { //if foo bar(); } }I started out coding using the Allman style, with aligned braces:
void foobar() { if(foo) { bar(); } }After decades I've decided I want that extra screen space; and besides, my client uses non-matched braces, so it's hard to switch back and forth from work to my personal code. So I want to convert all my existing code to K&R:
void foobar() { if(foo) { bar(); } }Eclipse 4.4 has a sufficient code formatter, and if I select my source tree I can even format files in bulk. The problem is that if I have a line comment where a K&R brace would be, Eclipse will refuse to move the brace up a line, leaving me with a hodgepodge of coding styles:
void foobar() { if(foo) //if foo { bar(); } }How can I tell Eclipse to move the brace up, even if there is a comment on the line where the brace goes?
void foobar() { if(foo) { //if foo bar(); } }最满意答案
正则表达式替换文件; 更换
\)\s*(//.*)(\r?\n)(\s*)\{ 1 2 3有:
) {\2\3 \1\2更新(Garret Wilson):经过大量实验,理想的正则表达式替换解决了所有变化并满足了我的需求:
^([^/]*(?:\)|\>|do|else|Exception|static|try))\s*(//.*)(\r?\n)(\s*)\{替换为:
\1 { \2A regular expression replacement over files; replace
\)\s*(//.*)(\r?\n)(\s*)\{ 1 2 3with:
) {\2\3 \1\2Update (Garret Wilson): After much experimentation, the ideal regular expression replacement that addressed all the variations and met my needs was:
^([^/]*(?:\)|\>|do|else|Exception|static|try))\s*(//.*)(\r?\n)(\s*)\{replaced with:
\1 { \2更多推荐
发布评论