54 protected $input =
'';
55 protected $inputIndex = 0;
56 protected $inputLength = 0;
57 protected $lookAhead = null;
58 protected $output =
'';
62 public static function minify($js) {
63 $jsmin =
new JSMin($js);
69 public function __construct($input) {
70 $this->input = str_replace(
"\r\n",
"\n", $input);
71 $this->inputLength = strlen($this->input);
76 protected function action($d) {
79 $this->output .= $this->a;
84 if ($this->a ===
"'" || $this->a ===
'"') {
86 $this->output .= $this->a;
87 $this->a = $this->
get();
89 if ($this->a === $this->b) {
93 if (ord($this->a) <= self::ORD_LF) {
97 if ($this->a ===
'\\') {
98 $this->output .= $this->a;
99 $this->a = $this->
get();
105 $this->b = $this->next();
107 if ($this->b ===
'/' && (
108 $this->a ===
'(' || $this->a ===
',' || $this->a ===
'=' ||
109 $this->a ===
':' || $this->a ===
'[' || $this->a ===
'!' ||
110 $this->a ===
'&' || $this->a ===
'|' || $this->a ===
'?')) {
112 $this->output .= $this->a . $this->b;
115 $this->a = $this->
get();
117 if ($this->a ===
'/') {
119 } elseif ($this->a ===
'\\') {
120 $this->output .= $this->a;
121 $this->a = $this->
get();
122 } elseif (ord($this->a) <= self::ORD_LF) {
127 $this->output .= $this->a;
130 $this->b = $this->next();
135 protected function get() {
136 $c = $this->lookAhead;
137 $this->lookAhead = null;
140 if ($this->inputIndex < $this->inputLength) {
141 $c = substr($this->input, $this->inputIndex, 1);
142 $this->inputIndex += 1;
152 if ($c === null || $c ===
"\n" || ord($c) >= self::ORD_SPACE) {
159 protected function isAlphaNum($c) {
160 return ord($c) > 126 || $c ===
'\\' || preg_match(
'/^[\w\$]$/', $c) === 1;
163 protected function min() {
167 while ($this->a !== null) {
170 if ($this->isAlphaNum($this->b)) {
192 if ($this->isAlphaNum($this->b)) {
204 if ($this->isAlphaNum($this->a)) {
225 if ($this->isAlphaNum($this->a)) {
241 return $this->output;
244 protected function next() {
248 switch($this->peek()) {
253 if (ord($c) <= self::ORD_LF) {
262 switch($this->
get()) {
264 if ($this->peek() ===
'/') {
283 protected function peek() {
284 $this->lookAhead = $this->
get();
285 return $this->lookAhead;