Changeset View
Changeset View
Standalone View
Standalone View
externals/JsShrink/jsShrink.php
| <?php | <?php | ||||
| /** Remove spaces and comments from JavaScript code | /** Remove spaces and comments from JavaScript code | ||||
| * @param string code with commands terminated by semicolon | * @param string code with commands terminated by semicolon | ||||
| * @return string shrinked code | * @return string shrinked code | ||||
| * @link http://vrana.github.com/JsShrink/ | * @link http://vrana.github.com/JsShrink/ | ||||
| * @author Jakub Vrana, http://www.vrana.cz/ | * @author Jakub Vrana, http://www.vrana.cz/ | ||||
| * @copyright 2007 Jakub Vrana | * @copyright 2007 Jakub Vrana | ||||
| * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 | * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 | ||||
| * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other) | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other) | ||||
| */ | */ | ||||
| function jsShrink($input) { | function jsShrink($input) { | ||||
| return preg_replace_callback('( | return preg_replace_callback('( | ||||
| (?: | (?: | ||||
| (^|[-+\([{}=,:;!%^&*|?~]|/(?![/*])|return|throw) # context before regexp | (^|[-+\([{}=,:;!%^&*|?~]|/(?![/*])|return|throw) # context before regexp | ||||
| (?:\s|//[^\n]*+\n|/\*(?:[^*]|\*(?!/))*+\*/)* # optional space | (?:\s|//[^\n]*+\n|/\*(?:[^*]|\*(?!/))*+\*/)* # optional space | ||||
| (/(?![/*])(?:\\\\[^\n]|[^[\n/\\\\]|\[(?:\\\\[^\n]|[^]])++)+/) # regexp | (/(?![/*])(?: | ||||
| \\\\[^\n] | |||||
| |[^[\n/\\\\]++ | |||||
| |\[(?:\\\\[^\n]|[^]])++ | |||||
| )+/) # regexp | |||||
| |(^ | |(^ | ||||
| |\'(?:\\\\.|[^\n\'\\\\])*\' | |\'(?:\\\\.|[^\n\'\\\\])*\' | ||||
| |"(?:\\\\.|[^\n"\\\\])*" | |"(?:\\\\.|[^\n"\\\\])*" | ||||
| |([0-9A-Za-z_$]+) | |([0-9A-Za-z_$]+) | ||||
| |([-+]+) | |([-+]+) | ||||
| |. | |. | ||||
| ) | ) | ||||
| )(?:\s|//[^\n]*+\n|/\*(?:[^*]|\*(?!/))*+\*/)* # optional space | )(?:\s|//[^\n]*+\n|/\*(?:[^*]|\*(?!/))*+\*/)* # optional space | ||||
| Show All 21 Lines | |||||