示例#1
0
 /**
  * Process a comment and return a replacement
  * 
  * @param array $m regex matches
  * 
  * @return string   
  */
 protected static function _commentCB($m)
 {
     $m = $m[1];
     // $m is the comment content w/o the surrounding tokens,
     // but the return value will replace the entire comment.
     if ($m === 'keep') {
         return '/**/';
     }
     if ($m === '" "') {
         // component of http://tantek.com/CSS/Examples/midpass.html
         return '/*" "*/';
     }
     if (preg_match('@";\\}\\s*\\}/\\*\\s+@', $m)) {
         // component of http://tantek.com/CSS/Examples/midpass.html
         return '/*";}}/* */';
     }
     if (self::$_inHack) {
         // inversion: feeding only to one browser
         if (preg_match('@
                 ^/               # comment started like /*/
                 \\s*
                 (\\S[\\s\\S]+?)  # has at least some non-ws content
                 \\s*
                 /\\*             # ends like /*/ or /**/
             @x', $m, $n)) {
             // end hack mode after this comment, but preserve the hack and comment content
             self::$_inHack = false;
             return "/*/{$n[1]}/**/";
         }
     }
     if (substr($m, -1) === '\\') {
         // comment ends like \*/
         // begin hack mode and preserve hack
         self::$_inHack = true;
         return '/*\\*/';
     }
     if ($m !== '' && $m[0] === '/') {
         // comment looks like /*/ foo */
         // begin hack mode and preserve hack
         self::$_inHack = true;
         return '/*/*/';
     }
     if (self::$_inHack) {
         // a regular comment ends hack mode but should be preserved
         self::$_inHack = false;
         return '/**/';
     }
     return '';
     // remove all other comments
 }
 /**
  * Process what looks like a comment and return a replacement
  * 
  * @param array $m regex matches
  * 
  * @return string   
  */
 protected static function _commentCB($m)
 {
     $m = $m[1];
     // $m is everything after the opening tokens and before the closing
     // tokens but return will replace the entire comment.
     if ($m === 'keep') {
         return '/*keep*/';
     }
     if (self::$_inHack) {
         // inversion: feeding only to one browser
         if (preg_match('/^\\/\\s*(\\S[\\s\\S]+?)\\s*\\/\\*/', $m, $n)) {
             self::$_inHack = false;
             return "/*/{$n[1]}/*keep*/";
         }
     }
     if (substr($m, -1) === '\\') {
         self::$_inHack = true;
         return '/*\\*/';
     }
     if ($m[0] === '/') {
         self::$_inHack = true;
         return '/*/*/';
     }
     if (self::$_inHack) {
         self::$_inHack = false;
         return '/*keep*/';
     }
     return '';
 }