user22097
user22097

Reputation: 229

Reformating c++ code?

How do I reformat the 'for' statement separated into three lines into one, in a automatically generated c++ code? I tried uncrustify, but I could not make it format the parts within parenthesis. sed seems not suitable for this. Could any one suggest me other formatter or some linux command that can take care of it?

Code to be formatted:

void func(double* s, Quaternion& a, int n)
{
 int size((n<4)?n:4);
 for (int i=0;
      i<size;
           i++)
 {
  a[i] = s[i];
 }
}

I want the 'for' statement above to be formatted into one line, like:

 for (int i=0; i<size; i++)

Upvotes: 0

Views: 243

Answers (2)

devnull
devnull

Reputation: 123528

You can make use of gnu indent.

Saying indent -npsl inputfile.c for your snippet would result in:

void func (double *s, Quaternion & a, int n)
{
  int size ((n < 4) ? n : 4);
  for (int i = 0; i < size; i++)
    {
      a[i] = s[i];
    }
}

The manual can be accessed here.

Upvotes: 1

mitchnull
mitchnull

Reputation: 6331

Try clang-format. It's kinda new, but a talk on GoingNative2013 showed promising results.

Upvotes: 2

Related Questions