Super easy to use code formatting tool Astyle

Posted by sONOCOOLO on Thu, 17 Feb 2022 13:02:18 +0100

This software is applicable to C, C++, C++/CLI, Objective ‑ C, C#, and Java

1, Use process

1. Install software

linux: apt install astyle, restart vscode

windows: Download the latest version , add the exe PATH to the PATH, and restart vscode

2. Install vscode plug-in Astyle

3. Configuration

Use: settings - > extension - > astyle - > in settings Edit in JSON (specific configuration attached)

Configuration diagram

"astyle.additional_languages": [
        "c",
        "cpp",
    ],
    "astyle.cmd_options": [
        "--style=allman",
        "--indent=spaces=4",
        "--indent-modifiers",
        "--indent-switches",
        "--indent-cases",
        "--indent-namespaces",
        "--indent-preproc-block",
        "--min-conditional-indent=2",
        "--pad-oper",
        "--pad-header",
        "--unpad-paren",
        "--delete-empty-lines",
        "--align-pointer=name",
        "--align-reference=name",
        "--keep-one-line-statements",
        "--convert-tabs",
        "--close-templates",
        /*"--max-code-length=#", Maximum length of single line code
        "--break-after-logical",*/
        "--suffix=none",
        "--lineend=linux",
        "--verbose",
    ],
    "[c]": {
        "editor.defaultFormatter": "chiehyu.vscode-astyle"
    },
    "[cpp]": {
        "editor.defaultFormatter": "chiehyu.vscode-astyle"
    },

(configuration reference: RT thread)

Specific configuration:

1. Brace options

--style=allman / --style=bsd / --style=break / -A1: separate brace style

int Foo(bool isBar)

{

    if (isBar)

    {

        bar();

        return 1;

    }

    else

        return 0;

}

--style=java / --style=attach / -A2: JAVA style -- attach braces

int Foo(bool isBar) {

    if (isBar) {

        bar();

        return 1;

    } else

        return 0;

}

--style=kr / --style=k/r / -A3: Linux style -- the opening brace is separated from the namespace, class, and function definitions. The remaining curly braces are appended to everything else within the function, including arrays, structs, enumerations, and statements.

int Foo(bool isBar)

{

    if (isBar) {

        bar();

        return 1;

    } else

        return 0;

}

--style=stroustrup / -A4: Stroustrup style - uses linux curly braces and separates the closing header from the closing header (for example: break - closing - headers). The opening brace is only disconnected from the function definition. The opening braces are appended to everything else in the function, including namespaces, classes, arrays, structures, enumerations, and statements. This style is often used with "attach - closing - while", tab indentation, and five space indentation.

int Foo(bool isBar)

{

    if (isBar) {

        bar();

        return 1;

    }

    else

        return 0;

}

--style=whitesmith / -A5: blacksmith style - use broken, indented brackets. Switch blocks and class blocks are indented to prevent the "hanging indentation" of the following case statements and c + + class modifiers (public, private, protected).

int Foo(bool isBar)

    {

    if (isBar)

        {

        bar();

        return 1;

        }

    else

        return 0;

    }

--style=ratliff / --style=banner / -A6: Ratliff style -- use additional, indented parentheses. Switch block and class block indentation is to prevent "hanging indentation" in the following case statements and c + + class modifiers (public, private, protected).

int Foo(bool isBar) {

    if (isBar) {

        bar();

        return 1;

        }

    else

        return 0;

    }

--style=gnu / -A7: GNU style - use broken parentheses. Additional indents are only added to blocks within the function. The entire block is indented, not just braces. This style is often used to indent 2 spaces.

int Foo(bool isBar)

{

    if (isBar)

        {

            bar();

            return 1;

        }

    else

        return 0;

}

--style=linux / --style=knf / -A8: Linux style -- use Linux braces. The opening braces are separated from namespace, class, and function definitions. Curly braces are attached to everything else inside the function, including arrays, structs, enumerations, and statements. The minimum conditional indentation is half indentation. If you want a different minimum conditional indentation, use the K & R style. This style is best for large indents. It is often used with indenting 8 spaces. Also known as the kernel paradigm (KNF) style, this is the style used in the Linux BSD kernel.

int Foo(bool isBar)

{

        if (isFoo) {

                bar();

                return 1;

        } else

                return 0;

}

--Style = Horstmann / -- style = run in / - A9: Horstmann style -- use broken parentheses and insert statements. The switch is turned on to allow running in. This style often uses an indent of three spaces.

int Foo(bool isBar)

{   if (isBar)

    {   bar();

        return 1;

    }

    else

        return 0;

}

--style=1tbs / --style=otbs / -A10: One True Brace style -- use linux curly braces and add curly braces to the condition statement without braces. The opening braces are separated from namespace, class, and function definitions. Curly braces are attached to everything else inside the function, including arrays, structs, enumerations, and statements.

int Foo(bool isBar)

{

    if (isFoo) {

        bar();

        return 1;

    } else {

        return 0;

    }

}

--style=pico / -A11: Pico style -- use broken braces and run in statements with additional closed braces. The closing brace is appended to the last line of the code block. The switch is indented to allow running in on the open switch block. This style means keeping one line of blocks and one line of statements. If add braces are used, they are added as a line of braces. This style is often used to indent 2 spaces.

int Foo(bool isBar)

{   if (isBar)

    {   bar();

        return 1; }

    else

        return 0; }

--style=lisp / --style=python / -A12: Lisp style -- use additional open and closed parentheses. The closing brace is appended to the last line of the code block. This style means keeping one line of statements, not one line of blocks. Single line braces are not supported in this style. If add one line braces are used, they are added as multiline braces.

int Foo(bool isBar) {

    if (isBar) {

        bar()

        return 1; }

    else

        return 0; }

--style=google / -A14: Google style - use additional curly braces and indented class access modifiers. For an example of the indent modifier format, see indent modifier options. This is actually not the only curly brace style, but a Java style with non curly brace variants. This style is often used to indent 2 spaces.

int Foo(bool isBar) {

    if (isBar) {

        bar();

        return 1;

    } else

        return 0;

}

--style=vtk / -A15: VTK style - use broken, indented braces, except for the left braces for class, array, structure, enumeration, and function definitions. Switch block indentation is to prevent "hanging indentation" in the following case statement.

int Foo(bool isBar)

{

    if (isBar)

        {

        bar();

        return 1;

        }

    else

        return 0;

}

--style=mozilla / -A16: Mozilla style -- use linux braces. The opening braces are separated from classes, structs, enumerations, and function definitions. Curly braces are attached to everything else in the function, including namespaces, arrays, and statements. This style is often used with indenting 2 spaces and -- break return type.

int Foo(bool isBar)

{

    if (isBar) {

        bar();

        return 1;

    } else

        return 0;

}

 

2.Tab options

default indent (if the indent option is not set, the default option of 4 spaces will be used (eg:: - S4 / - indent = spaces = 4)

void Foo() {

....if (isBar1

............&& isBar2)    // indent of this line can be changed with min-conditional-indent

........bar();

}

--indent=spaces / --indent=spaces=# / -s #: use # spaces for each indentation (eg:: - S3 / - indent = spaces = 3)# Must be between 2 and 20. Do not specify the same as default indent

void Foo() {

...if (isBar1

.........&& isBar2)    // indent of this line can be changed with min-conditional-indent

......bar();

}

--indent=tab / --indent=tab=# / -t / -t #: indent with tabs and continue line alignment with spaces. This ensures that the code displays correctly regardless of the size of the viewer's tabs. Treat each indentation as a # space (for example, - t6 / - indent=tab=6)# Must be between 2 and 20. If not set #, indent is processed to 4 spaces.

with indent=tab:

void Foo() {

>   if (isBar1

>   ........&& isBar2)    // indent of this line can be changed with min-conditional-indent

>   >   bar();

}

with style=linux, indent=tab=8:

void Foo()

{

>       if (isBar1

>       ....&& isBar2)    // indent of this line can NOT be changed with style=linux

>       >       bar();

}

--Indent = force tab / -- indent = force tab = # / - t / - t #: use all tab indents if possible. If consecutive lines are not even tabs, spaces are added at the end. Treat each tab as a # space (for example - T6 / - indent = force tab = 6)# Must be between 2 and 20. If not set #, treat tabs as 4 spaces.

with indent=force-tab:

void Foo() {

>   if (isBar1

>   >   >   && isBar2)    // indent of this line can be changed with min-conditional-indent

>   >   bar();

}

--indent=force-tab-x / --indent=force-tab-x=# / -xT / -xT #: this force tab option allows the tab length to be set to a length different from the indent length. This may result in indents containing both tabs and spaces. If possible, tabs will be used for indentation. If tab indents cannot be used, spaces will be used instead. This option sets the tab length. Treat each tab as a # space (e.g. - xT6 / -- indent = force tab-x = 6). # must be between 2 and 20. If #, treat tabs as 8 spaces. In order to change the indent length from the default 4 spaces, the option "indent = force tab" must also be used.

with indent=force-tab-x (default tab length of 8 and default indent length of 4):

void Foo() {

....if (isBar1

>       ....&& isBar2)    // indent of this line can be changed with min-conditional-indent

>       bar();

}

 

3. Brace modifier options

--Attach namespaces / - xn: braces are always attached to namespace statements.

namespace FooName {

...

}

--Attach classes / - XC: braces are always attached to class statements.

class FooClass {

...

};

--All methods that are inlined with c + + - attach and c + + - attach to class only

class FooClass

{

    void Foo() {

    ...

    }

};

--attach-extern-c / -xk: append braces to an extern "C" statement with braces (c + + only)

#ifdef __cplusplus

extern "C" {

#endif

However, the function definition is formatted according to the required brace style:

extern "C" EXPORT void STDCALL Foo()

{}

--Attach closing while / - XV: append the 'while' of the 'do while' statement to the closing bracket. This takes precedence over the brace style and the break off brace option.

do

{

    bar();

    ++x;

}

while x == 1;

becomes:

do

{

    bar();

    ++x;

} while x == 1;

 

4. Indent options

--Indent classes / - C: indent 'class' and' struct 'access modifiers' public:', 'protected:' and 'private:' (c + + only)

class Foo

{

public:

    Foo();

    virtual ~Foo();

};

becomes:

class Foo

{

    public:

        Foo();

        virtual ~Foo();

};

--Indent modifiers / - XG: indent 'class' and' struct 'access modifiers' public:', 'protected:' and 'private:', indent half. If used with indented classes, this option is ignored. (c + + only)

class Foo

{

public:

    Foo();

    virtual ~Foo();

};

becomes:

class Foo

{

  public:

    Foo();

    virtual ~Foo();

};

--Indent switches / - s: indent the 'switch' block so that the 'case X:' statement is indented in the switch block. The entire case block is indented.

switch (foo)

{

case 1:

    a += 1;

    break;



case 2:

{

    a += 2;

    break;

}

}

becomes:

switch (foo)

{

    case 1:

        a += 1;

        break;



    case 2:

    {

        a += 2;

        break;

    }

}

--Indent cases / - K: indent the 'case X:' block from the 'case X:' header. Case statements that are not contained in blocks are not indented.

switch (foo)

{

    case 1:

        a += 1;

        break;



    case 2:

    {

        a += 2;

        break;

    }

}

becomes:

switch (foo)

{

    case 1:

        a += 1;

        break;



    case 2:

        {

            a += 2;

            break;

        }

}

--Indent namespaces / - N: add extra indents to namespace blocks

namespace foospace

{

class Foo

{

    public:

        Foo();

        virtual ~Foo();

};

}

becomes:

namespace foospace

{

    class Foo

    {

        public:

            Foo();

            virtual ~Foo();

    };

}

--Indent after parents / - Xu: indent after the line containing the opening parenthesis' ('or assignment' = ', including function definition, declaration and return statement.

void Foo(bool bar1,

         bool bar2)

{

    isLongFunction(bar1,

                   bar2);



    isLongVariable = foo1

                     || foo2;

}

becomes:

void Foo(bool bar1,

    bool bar2)

{

    isLongFunction(bar1,

        bar2);



    isLongVariable = foo1

        || foo2;

}

--Indent continuation = # / - xt#: sets the continuation indentation of the line ending with the starting parenthesis' ('or the assignment' = ', including the function definition and declaration. It also modifies the preceding indent and the following parenthesis options. # indicates a large number of indents. Valid values are integer values from 0 to 4. If this option is not used, the default value of 1 is used.

isLongVariable =

    foo1 ||

    foo2;



isLongFunction(

    bar1,

    bar2);

becomes (with indent-continuation=3):

isLongVariable =

            foo1 ||

            foo2;



isLongFunction(

            bar1,

            bar2);

--Indent labels / - L: add extra indents to labels so that they display 1 indent less than the current indent instead of refreshing to the left (default).

void Foo() {

    while (isFoo) {

        if (isFoo)

            goto error;

        ...

error:

        ...

        }}

becomes (with indented 'error:'):

void Foo() {

    while (isFoo) {

        if (isFoo)

            goto error;

        ...

    error:

        ...

        }

}

--Indent Preproc block / - XW: indent the preprocessor block at brace level 0 and immediately within the namespace. There are restrictions on the contents of indentation. Blocks in methods, classes, arrays, and so on are not indented. Blocks that contain braces or multiline definition 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: indents a multiline preprocessor definition ending with a backslash. It should be used with -- convert tabs to get the correct results. Well done, but you can't perform miracles in the fuzzy preprocessing definition. Without this option, the preprocessor statement will 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 Preproc cond / - XW: indent the preprocessing condition statement to the same level as the source code.

        isFoo = true;

#ifdef UNICODE

        text = wideBuff;

#else

        text = buff;

#endif

becomes:

        isFoo = true;

        #ifdef UNICODE

        text = wideBuff;

        #else

        text = buff;

        #endif

--indent-col1-comments / -Y: indent c + + comments from the first column. By default, c + + comments starting from the first column are assumed to be comment output code, not indented. This option will allow comments to be indented with the code.

void Foo()\n"

{// comment

    if (isFoo)

        bar();

}

becomes:

void Foo()\n"

{

    // comment

    if (isFoo)

        bar();

}

--min-conditional-indent=# / -m#:

Sets the minimum indentation to be added when the header consists of multiple lines. This indentation helps to easily separate the header from the subsequent command statement# The value of represents the number of indents and is the minimum value. The indent may be larger to align with the data of the previous row. Valid values are:

0 - no minimum indentation. These lines are aligned with the parentheses on the previous line.

1 - indent at least one additional indent.

2 - indent at least two additional indents.

3 - increase the order by at least half. This is used for large indents (for example, 8).

The default value is 2, with two additional indents.

// default setting makes this non-braced code clear

if (a < b

        || c > d)

    foo++;



// but creates an exaggerated indent in this braced code

if (a < b

        || c > d)

{

    foo++;

}

becomes (when setting --min-conditional-indent=0):

// setting makes this non-braced code less clear

if (a < b

    || c > d)

    foo++;



// but makes this braced code clearer

if (a < b

    || c > d)

{

    foo++;

}

--Max continuation indent = # / - M #: sets the maximum length of # spaces to indent continuation lines# Indicates the number of columns and cannot be less than 40 or greater than 120. If not set, the default value of 40 is used. This option prevents the continuation row from extending too far to the right. Setting a higher value will allow the code to expand further to the right.

fooArray[] = { red,

         green,

         blue };



fooFunction(barArg1,

         barArg2,

         barArg3);

becomes (with larger value):

fooArray[] = { red,

               green,

               blue };



fooFunction(barArg1,

            barArg2,

            barArg3);

4. Fill options

--Break blocks / - F: fill empty lines around the title block (e.g. 'if', 'for', 'while'...)

isFoo = true;

if (isFoo) {

    bar();

} else {

    anotherBar();

}

isBar = false;

becomes:

isFoo = true;



if (isFoo) {

    bar();

} else {

    anotherBar();

}



isBar = false;

--Break blocks = all / - F: fill empty lines around the title block (e.g. 'if', 'for', 'while'...) Process the closed header file block (e.g. 'else', 'catch') as a separate block.

isFoo = true;

if (isFoo) {

    bar();

} else {

    anotherBar();

}

isBar = false;

becomes:

isFoo = true;



if (isFoo) {

    bar();



} else {

    anotherBar();

}



isBar = false;

--Pad oper / - P: inserts a space around the operator. This also adds commas. If possible, the end of line comments will remain in the original column. Note that there is no option to cancel the pad. Once filled, they remain filled.

if (foo==2)

    a=bar((b-c)*a,d--);

becomes:

if (foo == 2)

    a = bar((b - c) * a, d--);

--Pad comma / - XG: insert space after comma. If pad oper is used, there is no need to add. The end of line comment remains in the original column.

if (isFoo(a,b))

    bar(a,b);

becomes:

if (isFoo(a, b))

    bar(a, b);

--Pad paren / - P: insert space padding outside and inside parentheses. The end of line comment remains in the original column.

if (isFoo((a+2), b))

    bar(a, b);

becomes:

if ( isFoo ( ( a+2 ), b ) )

    bar ( a, b );

--Pad paren out / - D: insert space padding only outside parentheses. Empty parentheses are not padded. If possible, the end of line comments will remain in the original column. This can use the following UNPAD paren to delete unnecessary space.

if (isFoo((a+2), b))

    bar(a, b);

becomes:

if (isFoo ( (a+2), b) )

    bar (a, b);

--Pad first paren out / - XD: insert space padding only outside the first parenthesis of the sequence. Empty parentheses are not padded. The end of line comment remains in the original column. You can use UNPAD paren to delete unnecessary space. If used with pad ‑ paren or pad ‑ paren ‑ out, this option is ignored.

if (isFoo((a+2), b))

    bar(a, b);

becomes:

if (isFoo ((a+2), b))

    bar (a, b);

--Pad paren in / - D: insert only spaces around parentheses inside. The end of line comment remains in the original column. This can use the following UNPAD paren to delete unnecessary space.

if (isFoo((a+2), b))

    bar(a, b);

becomes:

if ( isFoo( ( a+2 ), b ) )

    bar( a, b );

--Pad header / - H: insert space between titles (e.g. 'if', 'for', 'while'...) And the brackets below. The end of line comment remains in the original column. You can use UNPAD paren to remove unwanted spaces.

if(isFoo((a+2), b))

    bar(a, b);

becomes:

if (isFoo((a+2), b))

    bar(a, b);

--UNPAD paren / - U: remove the excess filling space on the inner and outer sides. The end of line comment remains in the original column.

if ( isFoo( ( a+2 ), b ) )

    bar ( a, b );

becomes (with no padding option requested):

if(isFoo((a+2), b))

    bar(a, b);

--Delete empty lines / - Xe: delete empty lines in a function or method. Empty lines outside the function or method are not deleted. If used with break blocks or break blocks = all, it deletes all rows except those added by the break blocks option.

void Foo()

{



    foo1 = 1;



    foo2 = 2;



}

becomes:

void Foo()

{

    foo1 = 1;

    foo2 = 2;

}

--Fill empty lines / - E: fill an empty line with the blank space of the previous line.

--align-pointer=type   / -k1

--align-pointer=middle / -k2

--align-pointer=name   / -k3

Attach a pointer or reference operator (*, & or ^) to the variable type (left) or variable name (right), or place it between the type and name (middle). If possible, spaces between types and names are preserved. This option applies to C/ c + +, c++ /CLI, and c# files. To format the reference separately, use the following align reference option.

char* foo1;

char & foo2;

string ^s1;

becomes (with align-pointer=type):

char* foo1;

char& foo2;

string^ s1;

char* foo1;

char & foo2;

string ^s1;

becomes (with align-pointer=middle):

char * foo1;

char & foo2;

string ^ s1;

char* foo1;

char & foo2;

string ^s1;

becomes (with align-pointer=name):

char *foo1;

char &foo2;

string ^s1;

--align-reference=none   / -W0

--align-reference=type   / -W1

--align-reference=middle / -W2

--align-reference=name   / -W3

This option aligns the reference separately from the pointer. The pointer will not be changed by this option. If the pointer and reference are to be aligned, use the previous align pointer option. The option align reference = none does not change the reference alignment. The other options are the same as the alignment pointer. (C/ C + +, c++ /CLI and c# files only).

char &foo1;

becomes (with align-reference=type):

char& foo1;

char& foo2;

becomes (with align-reference=middle):

char & foo2;

char& foo3;

becomes (with align-reference=name):

char &foo3;

 

5. Formatting options

--Break closing braces / - Y: when used with -- style=java, --style=kr, --style=stroustrup, --style=linux, or -- style=1tbs, it will break the closing header file (e.g. 'else', 'catch',...)  . Closing Title curly braces are always broken with other styles.

void Foo(bool isFoo) {

    if (isFoo) {

        bar();

    } else {

        anotherBar();

    }}

becomes (a broken 'else'):

void Foo(bool isFoo) {

    if (isFoo) {

        bar();

    }

    else {

        anotherBar();

    }

}

--Break else IFS / - E: separate the "else if" header combination into separate rows. If you use the keep one line statement, this option is invalid, and the "else if" statement will remain the same.

If you do not use this option, the else If heading combination will be placed on a single line.

if (isFoo) {

    bar();

}

else if (isFoo1()) {

    bar1();

}

else if (isFoo2()) {

    bar2;

}

becomes:

if (isFoo) {

    bar();

}

else

    if (isFoo1()) {

        bar1();

    }

    else

        if (isFoo2()) {

            bar2();

        }

--Break one line headers / - Xb: break a line header from a statement on the same line (e.g. 'if', 'while', 'else',...) If the statement is enclosed in braces, the braces are formatted according to the required brace style. If you use keep one line statements, multiple statement lines will not be broken. If you use keep one line blocks and the header is contained in a block, a line of blocks will not be broken.

void Foo(bool isFoo)

{

    if (isFoo1) bar1();



    if (isFoo2) { bar2(); }}

becomes:

void Foo(bool isFoo)

{

    if (isFoo1)

        bar1();



    if (isFoo2) {

        bar2();

    }

}

--Add braces / - J: add braces to single line conditional statements without braces (for example: "if", "yes", "and"...). Braces will be added according to the required brace style. If no style is required, braces are appended. If you use keep one line statements, braces are not added to multiple statement lines. If you use keep one line blocks, curly braces are not added to a line of blocks. If used with -- add one line braces, the result will be a line of braces.

if (isFoo)

    isFoo = false;

becomes:

if (isFoo) {

    isFoo = false;

}

--Add one line braces / - J: add a line of braces to a line of conditional statements without braces (e.g. 'if', 'for', 'while'...). This option means -- keep one line blocks and will not break a line of blocks.

if (isFoo)

    isFoo = false;

becomes:

if (isFoo)

    { isFoo = false; }

--Remove braces / - XJ: remove parentheses from conditional statements (e.g. "if", "yes", "and"...). The statement must be a single statement on a single line. If you also use -- add braces or -- add one line braces, the result will be to add braces. Braces are not removed from "One True Brace Style" -- style=1tbs.

if (isFoo)

{

    isFoo = false;

}

becomes:

if (isFoo)

    isFoo = false;

--break-return-type      / -xB

--break-return-type-decl / -xD

Detach the return type from the function name. These two options are used for function definition (- xB) and function declaration or signature (- xD). If used with -- attach return type, the result will destroy the return type.

void Foo(bool isFoo);

becomes:

void

Foo(bool isFoo);

--attach-return-type      / -xf

--attach-return-type-decl / -xh

Append the return type to the function name. These two options are used for function definition (- xf) and function declaration or signature (- xh). Their purpose is to undo the -- break return type option. If used with -- break return type, the result will break the return type.

void

Foo(bool isFoo);

becomes:

void Foo(bool isFoo);

--keep-one-line-blocks / -O: don't break a line of code.

if (isFoo)

{ isFoo = false; cout << isFoo << endl; }

remains unchanged.

--keep-one-line-statements / -o: don't break complex statements and multiple statements that reside on a line.

if (isFoo)

{

    isFoo = false; cout << isFoo << endl;

}

remains unchanged.

--Convert tabs / - C: converts tabs to spaces in the non indented portion of the line. The number of spaces inserted will maintain Tab spacing. Use the current settings for the spaces in each Tab. If you use convert tabs when changing the space of each Tab, you may not produce the expected results. Tabs are not replaced within quotation marks.

--Close templates / - XY: close the space between the closing angle brackets of the template definition.

Stack< int, List< int > > stack1;

becomes:

Stack< int, List< int >> stack1;

--Remove comment prefix / - XP: delete the preceding '*' in a multiline comment that begins with one line. If there is' * 'at the end, it will also be deleted. Text less than one indentation is indented as one indentation. Do not change text larger than one indent. Multiline comments without '*' at the beginning of a line are indented into one indent to maintain consistency. This slightly modifies the indentation of the comment block. Rows containing all '*' remain unchanged. The comment closing '* /' will remove additional spaces.

/*

* comment line 1

* comment line 2

*/

becomes:

/*

    comment line 1

    comment line 2

*/

--max-code-length=#   / -xC#

--break-after-logical / -xL

If the code exceeds # characters, the option max ‑ code ‑ length will be broken. Valid values are 50 to 200. Lines without logical conditions break at logical conditions (|, & &,...), commas, parentheses, semicolons, or spaces. Some code will not be broken, such as comments, quotes, and arrays. If used with keep ‑ one ‑ line ‑ blocks or add one line braces, the block will not be destroyed. When used with keep ‑ one ‑ line ‑ statements, statements are separated by semicolons when the line exceeds the maximum length. If no breakpoint is available within the maximum code length, the line is broken at the first available breakpoint after the maximum code length. By default, the logical condition is placed first on the new row. The option break ‑ after ‑ logical will cause the logical condition to be placed at the end of the previous line. This option does not work if there is no maximum code length.

if (thisVariable1 == thatVariable1 || thisVariable2 == thatVariable2 || thisVariable3 == thatVariable3)

    bar();

becomes:

if (thisVariable1 == thatVariable1

        || thisVariable2 == thatVariable2

        || thisVariable3 == thatVariable3)

    bar();

becomes (with break‑after‑logical):

if (thisVariable1 == thatVariable1 ||

        thisVariable2 == thatVariable2 ||

        thisVariable3 == thatVariable3)

    bar();

--mode=c

--mode=cs

--mode=java

Indent a C-type, c# or Java file. C type files include C, C + +, c++ /CLI and Objective-C. This option is usually set from the file extension of each file. You can override this setting with this entry. It will be used for all files, regardless of the file extension. It allows formatters to recognize language specific syntax, such as C + + classes, templates, and keywords.

 

Topics: C++ Code Style