Find a token trying to avoid false positives

@param string $str   String containing the token
@param string $token Token being checked
@return bool
17524
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;
    }
773092
public function checkEncoding($str, $charset)
    {
        $mb = $this->getMbCharset($charset);
        if ($mb !== false) {
            return mb_check_encoding($str, $mb);
        }
        $ic = $this->getIconvAlias($charset);
        return (@iconv($ic, $ic, $str) !== false);
    }
756245
public static function findByEmailToken($token)
    {
        if (!static::isEmailTokenValid($token)) {
            return null;
        }
        return static::find()->where(['email_token' => $token, 'status' => self::STATUS_ACTIVE])->limit(1)->one();
    }
845713
public static function checkCardNumber(string $str) : bool
    {
        $str = strrev(preg_replace('/[^0-9]/','', $str));
        $chk = 0;
        for ($i = 0; $i < strlen($str); $i++) {
            $tmp = intval($str[$i]) * (1 + $i%2);
            $chk += $tmp - ($tmp>9?9:0);
        }
        return !($chk%10);
    }
581634
private function validateBool(string $str) : bool
    {
        $ret = filter_var($str,FILTER_VALIDATE_BOOLEAN);
        if ($ret === null){
            throw new CompileErrorException('invalid boolean value', $this->state);
        }
        return $ret;
    }
986269
public function parse($str, $context = null)
    {
        $this->lexer->setInput($str);
        $this->context = $context;

        $rs = $this->parseInternal();

        if (null !== $this->lexer->next) {
            $this->syntaxError('end of input');
        }

        return $rs;
    }
1355823
public function check($str, $hash) {
    $crypto  = $this->psl['crypt/crypto'];
    $compare = $this->psl['string/compare'];

    $hashInfo = $this->getInfo($hash);

    switch($hashInfo['algo']) {
      case self::PBKDF2:
        $param = array();
        list( , , $params, $hash, $salt) = explode('$', $hash);
        parse_str($params, $param);

        return $compare->timingSafe($crypto->pbkdf2($str, base64_decode($salt), $param['c'], $param['dk'], $param['f']), base64_decode($hash));
      break;

      case self::DRUPAL:
        $test = strpos($this->phpassHash($str, $hash), $hash);
        if($test === false || $test !== 0) {
        	return false;
        }
        return true;
      break;

      case self::BCRYPT;
      case self::BCRYPT_BC;
      case self::SHA256:
      case self::SHA512:
        return $compare->timingSafe(crypt($str, $hash), $hash);
      break;

      default:
        /* Not any of the supported formats. Try plain hash methods. */
      	$hashLen = strlen($hash);
      	switch($hashLen) {
      		case 32:
        	  $mode = 'md5';
      	  break;
      		case 40:
      		  $mode = 'sha1';
      	  break;
      		case 64:
            $mode = 'sha256';
          break;
      		case 128:
      		  $mode = 'sha512';
      		break;
      		default:
      		  return false;
      	}
      	return $compare->timingSafe(hash($mode, $str), $hash);
      break;
    }
  }
970740
public static function isNumberStr($str)
    {
        return !is_resource($str) && !is_array($str) && !is_object($str) && (is_int($str) || is_numeric($str) || preg_match('/^\d*$/', $str));
    }
875866
private function match($token)
    {
        if ( ! $this->lexer->isNextToken($token) ) {
            $this->syntaxError($this->lexer->getLiteral($token));
        }

        return $this->lexer->moveNext();
    }
1319833
public static function isAlphaNum($str)
    {
        if (!is_string($str)) {
            throw new \ErrorException('Accept string ' . gettype($str) . ' given');
        }

        return (bool) preg_match('/^[a-zA-Z0-9]+$/', $str);
    }
400585
public static function validate($token)
    {
        if ($token === null) {
            return false;
        }

        if (gettype($token) == 'string' && trim($token) == '') {
            // False if String Empty
            return false;
        }

        if (strlen($token) < 20) return false;
        if (strlen($token) > 50) return false;

        // Type 0: c0afcccdde5081d6429de37d16166ead
        $type0RegExpression = '/(^[a-z0-9]+$)/i';

        // Type 1: de305d54-75b4-431b-adb2-eb6b9e546014
        // UUID strict: http://en.wikipedia.org/wiki/Universally_unique_identifier#Definition
        $type1RegExpression = '/(^[a-f0-9]{8}\-[a-f0-9]{4}\-[a-f0-9]{4}\-[a-f0-9]{4}\-[a-f0-9]{12}$)/i';

        if (preg_match($type0RegExpression, $token) == false
            && preg_match($type1RegExpression, $token) == false
        ) {
            return false;
        }

        return true;
    }
1328955
public static function isKeyword($str, $isReserved = false)
    {
        $str = strtoupper($str);

        if (isset(static::$KEYWORDS[$str])) {
            if ($isReserved && ! (static::$KEYWORDS[$str] & Token::FLAG_KEYWORD_RESERVED)) {
                return null;
            }

            return static::$KEYWORDS[$str];
        }

        return null;
    }
640853
public function findAll($str) {
        $this->recvAll();
        $output_as_array = explode($this->retcarriage, $this->getBuffer());
        foreach ($output_as_array as $line) {
            if (preg_match("/{$str}/", $line, $matches)) {
                return $matches[0];
            }
        }
        return false;
    }
1116648
public static function isComment($str, $end = false)
    {
        $len = strlen($str);
        if ($len === 0) {
            return null;
        }
        if ($str[0] === '#') {
            return Token::FLAG_COMMENT_BASH;
        } elseif (($len > 1) && ($str[0] === '/') && ($str[1] === '*')) {
            return (($len > 2) && ($str[2] === '!')) ?
                Token::FLAG_COMMENT_MYSQL_CMD : Token::FLAG_COMMENT_C;
        } elseif (($len > 1) && ($str[0] === '*') && ($str[1] === '/')) {
            return Token::FLAG_COMMENT_C;
        } elseif (($len > 2) && ($str[0] === '-')
            && ($str[1] === '-') && static::isWhitespace($str[2])
        ) {
            return Token::FLAG_COMMENT_SQL;
        } elseif (($len === 2) && $end && ($str[0] === '-') && ($str[1] === '-')) {
            return Token::FLAG_COMMENT_SQL;
        }

        return null;
    }
1254951
private static function isValidXmlTagName($str)
    {
        static $validTagRegex = null;

        if ($validTagRegex === null) {
            $invalidTagChars = "!\"#$%&'()*+,\\/;<=>?@[\\]\\\\^`{|}~";
            $invalidTagStartChars = $invalidTagChars . "\\-.0123456789";
            $validTagRegex = "/^[^" . $invalidTagStartChars . "][^" . $invalidTagChars . "]*$/";
        }

        $result = preg_match($validTagRegex, $str);
        return !empty($result);
    }
513746
protected static function ourStrlen($str)
    {
        // Premature optimization: cache the function_exists() result
        static $exists = null;
        if ($exists === null) {
            $exists = \function_exists('\\mb_strlen');
        }

        // If it exists, we need to make sure we're using 8bit mode
        if ($exists) {
            return \mb_strlen($str, '8bit');
        }
        return \strlen($str);
    }
1366252
private function evalString($str)
    {
        $a = false;

        if (class_exists('ParseError')) {
            try {
                $a = eval("return $str;");
            } catch (ParseError $e) {
            }
        } else {
            $a = @eval("return $str;");
        }

        return $a;
    }