Skip to content

Instantly share code, notes, and snippets.

@cyborch
Created April 7, 2011 17:56
Show Gist options
  • Save cyborch/908323 to your computer and use it in GitHub Desktop.
Save cyborch/908323 to your computer and use it in GitHub Desktop.
While not a robust beautify library - this small snippet takes care of most cases
#!/usr/bin/perl
@_=<STDIN>;
$_=join("",@_);
# fix K&R style code
s/\s*\n\s*{/ {/gs;
s/}\s*\n\s*else/} else/gs;
s/ ?\){/\) {/g;
# convert "if( something ){" to "if (something) {"
s/if\( ?/if \(/g;
# ensure that "{" at end of line is preceeded by a space
s/([^ ]){\n/$1 {\n/gs;
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment