From a2ab786bacec49b878f2e64b69794224b1a40833 Mon Sep 17 00:00:00 2001 From: Harvie Date: Mon, 1 Nov 2010 17:09:37 +0100 Subject: [PATCH] Added PHP beautifier: will process whole code through it once i'll test it properly... --- scripts/beautify.php | 101 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100755 scripts/beautify.php diff --git a/scripts/beautify.php b/scripts/beautify.php new file mode 100755 index 0000000..787f238 --- /dev/null +++ b/scripts/beautify.php @@ -0,0 +1,101 @@ +#!/usr/bin/php +//Downloaded from http://shadsplace.org/beautify-php/beautify.phps +=0;$i--){ + $placeholders[$i]="/".$placeholders[$i]."/"; + } + + if ($placeholders){ + $str=preg_replace($placeholders, $matches[0], $str); + + } + return $str; +} +function privateParseString($str) +{ + // inserting missing braces (does only match up to 2 nested parenthesis) + $str=preg_replace("/(if|for|while|switch)\s*(\([^()]*(\([^()]*\)[^()]*)*\))([^{;]*;)/i", "\\1 \\2 {\\4\n}", $str); + // missing braces for else statements + $str=preg_replace("/(else)\s*([^{;]*;)/i", "\\1 {\\2\n}", $str); + + // line break check + $str=preg_replace("/([;{}]|case\s[^:]+:)\n?/i", "\\1\n", $str); + $str=preg_replace("/^function\s+([^\n]+){/mi", "function \\1\n{", $str); + + // remove inserted line breaks at else and for statements + $str=preg_replace("/}\s*else\s*/m", "} else ", $str); + $str=preg_replace("/(for\s*\()([^;]+;)(\s*)([^;]+;)(\s*)/mi", "\\1\\2 \\4 ", $str); + + // remove spaces between function call and parenthesis and start of argument list + $str=preg_replace("/(\w+)\s*\(\s*/", "\\1(", $str); + + // remove line breaks between condition and brace, + // set one space between control keyword and condition + $str=preg_replace("/(if|for|while|switch)\s*(\([^{]+\))\s*{/i", "\\1 \\2 {", $str); + + return $str; +} +function privateIndentParsedString($str, $indent) +{ + $count = substr_count($str, '}')-substr_count($str, '{'); + if ($count<0){ + $count = 0; + } + + $strarray=explode("\n", $str); + + for($i=0;$i -- 2.30.2