Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Is it possible to obtain switch statements formatted as:

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

with Clang-Format?

like image 807
Emerald Weapon Avatar asked Sep 17 '25 03:09

Emerald Weapon


1 Answers

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

like image 79
Vittorio Romeo Avatar answered Sep 19 '25 19:09

Vittorio Romeo