views:

29

answers:

1

This kind of code structure makes, IMHO, code less readable:

int func() {
  [...]
}

It's just a matter of taste, but I prefer this one:

int func()
{
  [...]
}

So I've trying to make a regular expression to apply in my text editor in order to make code in the first example look like the second one.

I've come up with something like ^([\t]*)([^\t{]*)({.*)$ ( I don't remember exactly if it was like this )
The idea is that when a { is found preceded of non-space characters, most probably the function header or a control structure, then split the line and send the { to the next line, but preserving the indent level (I.E. the same amount of tabs) of the original line.

The last part, about keeping the indent level is what I can't get right.
Any help appreciated.

--
PS: Feel free to disagree with my coding standards but please remember that's not the main subject here.

A: 

Ok, closing this one.

Petruza