lib/Minify/Lines.php
private static function _find($str, $token)
    {
        switch ($token) {
            case '//':
                $fakes = array(
                    '://' => 1,
                    '"//' => 1,
                    '\'//' => 1,
                    '".//' => 2,
                    '\'.//' => 2,
                );
                break;
            case '/*':
                $fakes = array(
                    '"/*' => 1,
                    '\'/*' => 1,
                    '"//*' => 2,
                    '\'//*' => 2,
                    '".//*' => 3,
                    '\'.//*' => 3,
                    '*/*' => 1,
                    '\\/*' => 1,
                );
                break;
            default:
                $fakes = array();
        }

        $index = strpos($str, $token);
        $offset = 0;

        while ($index !== false) {
            foreach ($fakes as $fake => $skip) {
                $check = substr($str, $index - $skip, strlen($fake));
                if ($check === $fake) {
                    // move offset and scan again
                    $offset += $index + strlen($token);
                    $index = strpos($str, $token, $offset);
                    break;
                }
            }
            // legitimate find
            return $index;
        }

        return $index;
    }
private static function _find($str, $token)
    {
        switch ($token) {
            case '//':
                $fakes = array(
                    '://' => 1,
                    '"//' => 1,
                    '\'//' => 1,
                    '".//' => 2,
                    '\'.//' => 2,
                );
                break;
            case '/*':
                $fakes = array(
                    '"/*' => 1,
                    '\'/*' => 1,
                    '"//*' => 2,
                    '\'//*' => 2,
                    '".//*' => 3,
                    '\'.//*' => 3,
                    '*/*' => 1,
                    '\\/*' => 1,
                );
                break;
            default:
                $fakes = array();
        }

        $index = strpos($str, $token);
        $offset = 0;

        while ($index !== false) {
            foreach ($fakes as $fake => $skip) {
                $check = substr($str, $index - $skip, strlen($fake));
                if ($check === $fake) {
                    // move offset and scan again
                    $offset += $index + strlen($token);
                    $index = strpos($str, $token, $offset);
                    break;
                }
            }
            // legitimate find
            return $index;
        }

        return $index;
    }
private static function _find ( $ str , $ token ) { switch ( $ token ) { case '//' : $ fakes = array ( '://' => 1 , '"//' => 1 , '\'//' => 1 , '".//' => 2 , '\'.//' => 2 , ) ; break ; case '/*' : $ fakes = array ( '"/*' => 1 , '\'/*' => 1 , '"//*' => 2 , '\'//*' => 2 , '".//*' => 3 , '\'.//*' => 3 , '*/*' => 1 , '\\/*' => 1 , ) ; break ; default : $ fakes = array ( ) ; } $ index = strpos ( $ str , $ token ) ; $ offset = 0 ; while ( $ index !== false ) { foreach ( $ fakes as $ fake => $ skip ) { $ check = substr ( $ str , $ index - $ skip , strlen ( $ fake ) ) ; if ( $ check === $ fake ) { // move offset and scan again $ offset += $ index + strlen ( $ token ) ; $ index = strpos ( $ str , $ token , $ offset ) ; break ; } } // legitimate find return $ index ; } return $ index ; }
Find a token trying to avoid false positives

@param string $str   String containing the token
@param string $token Token being checked
@return bool
Find a token trying to avoid false positives