Вопрос

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++)
Это было полезно?

Решение 2

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.

Другие советы

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top