/** * Run the JSMin application : minify some JS code. * * The code is read from the input stream, and its minified version is written to the output one. * In case input is a string, minified vesrions is also returned by this function as string. * That is : characters which are insignificant to JavaScript are removed, as well as comments ; * tabs are replaced with spaces ; carriage returns are replaced with linefeeds, and finally most * spaces and linefeeds are deleted. * * Note : name was changed from jsmin() because PHP identifiers are case-insensitive, and it is already * the name of this class. * * @see JSMin() * @return null | string */ function minify() { // Initialize A and run the first (minimal) action $this->theA = "\n"; $this->action(JSMIN_ACT_IMM); // Proceed all the way to the end of the input file while ($this->theA !== EOF) { switch ($this->theA) { case ' ': if (JSMin::isAlphaNum($this->theB)) { $this->action(JSMIN_ACT_FULL); } else { $this->action(JSMIN_ACT_BUF); } break; case "\n": switch ($this->theB) { case '{': case '[': case '(': case '+': case '-': $this->action(JSMIN_ACT_FULL); break; case ' ': $this->action(JSMIN_ACT_IMM); break; default: if (JSMin::isAlphaNum($this->theB)) { $this->action(JSMIN_ACT_FULL); } else { $this->action(JSMIN_ACT_BUF); } break; } break; default: switch ($this->theB) { case ' ': if (JSMin::isAlphaNum($this->theA)) { $this->action(JSMIN_ACT_FULL); break; } // else $this->action(JSMIN_ACT_IMM); break; case "\n": switch ($this->theA) { case '}': case ']': case ')': case '+': case '-': case '"': case '\'': $this->action(JSMIN_ACT_FULL); break; default: if (JSMin::isAlphaNum($this->theA)) { $this->action(JSMIN_ACT_FULL); } else { $this->action(JSMIN_ACT_IMM); } break; } break; default: $this->action(JSMIN_ACT_FULL); break; } break; } } if ($this->isString) { return $this->out; } }