95% of use cases for "INDENT-OFF" in my code are for switch statements:
Astyle converts this:
std::wstring formatHttpError(int sc)
{
switch (sc)
{
case 300: return L"Multiple choices.";
case 301: return L"Moved permanently.";
case 302: return L"Moved temporarily.";
case 303: return L"See other";
case 304: return L"Not modified.";
}
switch (c)
{
case '&': output += "&" ; break;
case '"': output += """; break;
case '<': output += "<" ; break;
case '>': output += ">" ; break;
default: output += c; break;
}
}
to this:
std::wstring formatHttpError(int sc)
{
switch (sc)
{
case 300:
return L"Multiple choices.";
case 301:
return L"Moved permanently.";
case 302:
return L"Moved temporarily.";
case 303:
return L"See other";
case 304:
return L"Not modified.";
}
switch (c)
{
case '&':
output += "&" ;
break;
case '"':
output += """;
break;
case '<':
output += "<" ;
break;
case '>':
output += ">" ;
break;
default:
output += c;
break;
}
}
I prefer the former more succinct represenation. It would be great if Astyle had some option like "--preserve-switch-oneliners".
I guess there is no need/want to convert multi-line switch cases into a single line, but if they are already on a single line, they should be kept.
My Astyle config used:
Sorry, this should have been filed under "Feature Requests", not "Bugs".
I just realized there is "--keep-one-line-statements", and it works for switches, too!!
Ticket can be closed! :)