介绍一个 C/C++ 、C#、JAVA 代码美化工具

本文介绍了开源工具AStyle,支持C/C++、C#、JAVA等语言的代码格式化。通过提供各种选项,如--style=ansi、--indent=tab、--align-pointer=type等,可以定制代码风格。此外,还分享了如何将AStyle集成到VS中以及批量处理代码文件的方法。
摘要由CSDN通过智能技术生成

给大伙介绍一个开源工具 AStyle,支持C/C++、C#、JAVA等语言,按照不同的风格格式化代码,也可以称为美化代码。
用这个工具美化出来的代码与我自已的风格几乎一样,我很喜欢这个小工具,也可以很方便的集成到VS里面去。

用法:

AStyle.exe --style=ansi -t -M80 -k1 -p -j -H -c -w -n -U -K -Y -xW test.cpp


--style=ansi ansi C风格代码

void Foo(bool isFoo)
{
    if (isFoo)
    {
        bar();
    }
    else
    {
        anotherBar();
    }
}

--indent=tab / --indent=tab=# /-t / -t#  缩进用tab,不用空格,#为数字,默认为4

 

--indent-preproc-block /-xW
Indent preprocessor blocks at bracket level zero, and immediately within a namespace. There are restrictions on what will be indented. Blocks within methods, classes, arrays, etc, will not be indented. Blocks containing brackets or multi-line define statements will not be indented. Without this option the preprocessor block is not indented.

#ifdef _WIN32
#include <windows.h>
#ifndef NO_EXPORT
#define EXPORT
#endif
#endif

becomes:

#ifdef _WIN32
    #include <windows.h>
    #ifndef NO_EXPORT
        #define EXPORT
    #endif
#endif

--indent-preproc-define /-w
Indent multi-line preprocessor definitions ending with a backslash. Should be used with --convert-tabs for proper results. Does a pretty good job, but cannot perform miracles in obfuscated preprocessor definitions. Without this option the preprocessor statements remain unchanged.

#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)))


--indent-col1-comments /

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值