Clang-Format: how to get one-line case statements in a switch statement

3.4k views Asked by At

Is it possible to obtain switch statements formatted as:

switch (index) {
  case 0: /* statement */ break;
  case 1: /* statement */ break;
  default: break;
}

with Clang-Format?

1

There are 1 answers

1
Vittorio Romeo On BEST ANSWER

Yes, you need to set AllowShortCaseLabelsOnASingleLine to true. You can experiment in real-time with your .clang-format configuration on this great website: "clang-format-configurator".

Clang-format configurator screenshot