11<?php
2- /** Css Minifier - simple CSS minifier
3- *
4- * @author David Grudl, 2011
5- * @author Jan Pecha, <janpecha@email.cz>, 2012
6- * @license New BSD License
7- */
8-
2+
93 namespace Cz \CssMinifier ;
10-
4+
5+
116 class CssMinifier
127 {
13- const S_NORMAL = 0 ,
14- S_STRING = 1 ;
15-
16-
17-
8+ const S_NORMAL = 0 ;
9+ const S_STRING = 1 ;
10+
11+
1812 /**
1913 * @link https://github.com/nette/build-tools/blob/master/tasks/minifyJs.php#L51-L56
2014 * @author David Grudl, 2011
@@ -27,56 +21,49 @@ public function minify($s)
2721 $ s = preg_replace ('#\s+# ' , ' ' , $ s ); // compress space
2822 $ s = preg_replace ('# ([^(0-9a-z.\#*-])#i ' , '$1 ' , $ s );
2923 $ s = preg_replace ('#([^0-9a-z%)]) #i ' , '$1 ' , $ s );
30- while ( strpos ( $ s , ' ;} ' ) !== FALSE )
31- {
24+
25+ while ( strpos ( $ s , ' ;} ' ) !== FALSE ) {
3226 $ s = str_replace (';} ' , '} ' , $ s ); // remove leading semicolon
3327 }
28+
3429 $ s = trim ($ s );
35-
30+
3631 // replace SPACE => NEW LINE
3732 $ state = self ::S_NORMAL ;
3833 $ stringChar = '' ;
3934 $ lastChar = NULL ;
4035 $ len = strlen ($ s );
4136 $ buffer = '' ;
42-
43- for ($ i = 0 ; $ i < $ len ; $ i ++)
44- {
37+
38+ for ($ i = 0 ; $ i < $ len ; $ i ++) {
4539 $ currentChar = $ s [$ i ];
46- if ($ state === self ::S_NORMAL )
47- {
48- if ($ s [$ i ] === '\'' || $ s [$ i ] === '" ' )
49- {
40+
41+ if ($ state === self ::S_NORMAL ) {
42+ if ($ s [$ i ] === '\'' || $ s [$ i ] === '" ' ) {
5043 $ state = self ::S_STRING ;
5144 $ stringChar = $ s [$ i ];
52- }
53- elseif ($ s [$ i ] === ' ' )
54- {
45+
46+ } elseif ($ s [$ i ] === ' ' ) {
5547 //$s[$i] = "\n";
5648 $ buffer .= "\n" ;
5749 continue ;
58- }
59- elseif ($ s [$ i ] === '; ' )
60- {
61- if ($ lastChar === '; ' )
62- {
50+
51+ } elseif ($ s [$ i ] === '; ' ) {
52+ if ($ lastChar === '; ' ) {
6353 continue ;
6454 }
6555 }
66- }
67- elseif ($ state === self ::S_STRING )
68- {
69- if ($ lastChar !== '\\' && $ s [$ i ] === $ stringChar )
70- {
56+ } elseif ($ state === self ::S_STRING ) {
57+ if ($ lastChar !== '\\' && $ s [$ i ] === $ stringChar ) {
7158 $ state = self ::S_NORMAL ;
7259 $ stringChar = '' ;
7360 }
7461 }
75-
62+
7663 $ buffer .= $ lastChar = $ currentChar ;
7764 }
78-
65+
7966 return $ buffer ;
8067 }
8168 }
82-
69+
0 commit comments