Menu ▾ ▴

#461 Disable formatting in switch-case

open-accepted
None
1 day ago
2017-10-25
h264
No

If insert a disable block in switch-case, the case with curly brackets will be added a addition indentation on case's statement and }

  • Version : 3.0.1
  • Options : please refer to the attachment option file "astylec"
  • Language : C

For example:

Expected formatted output:

void func(int para)
{
    switch (para) {
    case 0: {
        init(ch);
        break;
    }

    case 1: {
        /* *INDENT-OFF* */
        for (int ch = 0; ch < TOTAL_CH; ch++) {
            init(ch);
        }
        /* *INDENT-ON* */

    break;
    }

    case 2: {
        init(ch);
        break;
    }

    default:
        init(ch);
        break;
    }
}

Actual formatted output:

void func(int para)
{
    switch (para) {
    case 0: {
        init(ch);
        break;
    }

    case 1: {
        /* *INDENT-OFF* */
        for (int ch = 0; ch < TOTAL_CH; ch++) {
            init(ch);
        }
        /* *INDENT-ON* */

            break;
        }

    case 2: {
            init(ch);
            break;
        }

    default:
        init(ch);
        break;
    }
}
1 Attachments

Discussion

  • h264

    h264 - 2017-10-25

    Besides, if place the disable block inside the for-statement, it also incorrect and output the different identation.

    Orginal

    void func(int para)
    {
        switch (para) {
        case 0: {
            init(ch);
            break;
        }
    
        case 1: {
            for (int ch = 0; ch < TOTAL_CH; ch++) {
                /* *INDENT-OFF* */
                init(ch);
                /* *INDENT-ON* */
            }
    
        break;
        }
    
        case 2: {
            init(ch);
            break;
        }
    
        default:
            init(ch);
            break;
        }
    }
    

    Formatted 3 times

    void func(int para)
    {
        switch (para) {
        case 0: {
            init(ch);
            break;
        }
    
        case 1: {
                for (int ch = 0; ch < TOTAL_CH; ch++) {
                /* *INDENT-OFF* */
    init(ch);
    /* *INDENT-ON* */
            }
    
            break;
            }
    
        case 2: {
                init(ch);
                break;
            }
    
        default:
            init(ch);
            break;
        }
    }
    
     
  • André Simon

    André Simon - 1 day ago
    • status: open --> open-accepted
    • assigned_to: André Simon
     

Log in to post a comment.