85 define(
'JSMIN_VERSION',
'0.2');
99 define(
'ORD_NL', ord(
"\n"));
100 define(
'ORD_space', ord(
' '));
101 define(
'ORD_cA', ord(
'A'));
102 define(
'ORD_cZ', ord(
'Z'));
103 define(
'ORD_a', ord(
'a'));
104 define(
'ORD_z', ord(
'z'));
105 define(
'ORD_0', ord(
'0'));
106 define(
'ORD_9', ord(
'9'));
155 define(
'JSMIN_ACT_FULL', 1);
161 define(
'JSMIN_ACT_BUF', 2);
167 define(
'JSMIN_ACT_IMM', 3);
210 public $inLength = 0;
212 public $isString =
false;
234 $c ===
'_' || $c ===
'$' || $c ===
'\\' || $a > 126
247 public function get()
252 if ($this->isString) {
253 if ($this->inPos < $this->inLength) {
254 $c = $this->in[$this->inPos];
260 $c = $this->in->fgetc();
265 if ($c ===
"\n" || $c ===
EOF || ord($c) >=
ORD_space) {
292 if ($this->isString) {
293 if ($this->inPos < $this->inLength) {
294 $c = $this->in[$this->inPos];
301 $c = $this->in->fgetc();
305 $this->in->fseek(-1, SEEK_CUR);
319 if ($this->isString) {
322 $this->out->fwrite($c);
348 switch ($this->peek()) {
379 if ($this->peek() ==
'/') {
386 } elseif ($c ===
EOF) {
391 trigger_error(
'UnterminatedComment', E_USER_ERROR);
435 $this->put($this->theA);
442 $tmpA = $this->theA = $this->theB;
447 if ($tmpA ==
'\'' || $tmpA ==
'"') {
458 $tmpA = $this->theA = $this->
get();
460 if ($tmpA == $this->theB) {
469 if (ord($tmpA) <=
ORD_NL) {
474 trigger_error(
'UnterminatedStringLiteral', E_USER_ERROR);
484 $tmpA = $this->theA = $this->
get();
494 $this->theB = $this->next();
501 if ($this->theB ==
'/' && ($tmpA ==
'(' || $tmpA ==
',' || $tmpA ==
'=')) {
506 $this->put($this->theB);
512 $tmpA = $this->theA = $this->
get();
528 $tmpA = $this->theA = $this->
get();
529 } elseif (ord($tmpA) <=
ORD_NL) {
534 trigger_error(
'UnterminatedRegExpLiteral', E_USER_ERROR);
544 $this->theB = $this->next();
550 trigger_error(
'Expected a JSMin::ACT_* constant in action()', E_USER_ERROR);
579 while ($this->theA !==
EOF) {
580 switch ($this->theA) {
593 switch ($this->theB) {
595 case '{':
case '[':
case '(':
620 switch ($this->theB) {
636 switch ($this->theA) {
638 case '}':
case ']':
case ')':
case '+':
639 case '-':
case '"':
case '\'':
667 if ($this->isString) {
682 public function __construct($inFileName =
'-', $outFileName =
'-', $comments = null)
684 if ($outFileName ===
false) {
685 $this->JSMin_String($inFileName, $comments);
687 $this->JSMin_File($inFileName, $outFileName, $comments);
691 public function JSMin_File($inFileName =
'-', $outFileName =
'-', $comments = null)
697 if ($inFileName ==
'-') {
698 $inFileName =
'php://stdin';
700 if ($outFileName ==
'-') {
701 $outFileName =
'php://stdout';
726 $this->in = fopen($inFileName,
'rb');
728 trigger_error(
'Failed to open "' . $inFileName, E_USER_ERROR);
730 $this->out = fopen($outFileName,
'wb');
732 trigger_error(
'Failed to open "' . $outFileName, E_USER_ERROR);
737 if ($comments !== null) {
738 foreach ($comments as $comm) {
739 $this->out->fwrite(
'// ' . str_replace(
"\n",
" ", $comm) .
"\n");
746 $this->in = $inString;
748 $this->inLength = strlen($inString);
750 $this->isString =
true;
752 if ($comments !== null) {
753 foreach ($comments as $comm) {
754 $this->out .=
'// ' . str_replace(
"\n",
" ", $comm) .
"\n";
JSMin_String($inString, $comments=null)
const JSMIN_ACT_BUF
Constant describing an action() : Copy B to A.
A JSMin exception indicatig that an unterminated string literal was encountered in input...
next()
Get the next character from the input stream, excluding comments.
JSMin_File($inFileName='-', $outFileName='-', $comments=null)
Generic exception class related to JSMin.
__construct($inFileName='-', $outFileName='-', $comments=null)
Prepare a new JSMin application.
isAlphaNum($c)
Indicates whether a character is alphanumeric or _, $, \ or non-ASCII.
const ORD_NL
Some ASCII character ordinals.
const JSMIN_ACT_IMM
Constant describing an action() : Get the next B.
A JSMin exception indicatig that an unterminated regular expression lieteral was encountered in input...
A JSMin exception indicating that a file provided for input or output could not be properly opened...
const JSMIN_ACT_FULL
Constant describing an action() : Output A.
action($action)
Do something !
put($c)
Adds a char to the output steram / string.
minify()
Run the JSMin application : minify some JS code.
Main JSMin application class.
peek()
Get the next character from the input stream, without gettng it.
const EOF
How fgetc() reports an End Of File.