@param string $userAgent

@return null|string
325560
public function applyConclusiveMatch($userAgent)
    {
        $idx       = strpos($userAgent, 'Nokia');
        $tolerance = Utils::indexOfAnyOrLength($userAgent, array('/', ' '), $idx);

        return $this->getDeviceIDFromRIS($userAgent, $tolerance);
    }
74508
private function chromeWithMajorVersion($userAgent) {
		$start_idx = strpos($userAgent, 'Chrome');
		$end_idx = strpos($userAgent, '.', $start_idx);
		if ($end_idx === false) {
			return substr($userAgent, $start_idx);
		} else {
			return substr($userAgent, $start_idx, ($end_idx - $start_idx));
		}
	}
648462
public function applyExactMatch($userAgent)
    {
        if (array_key_exists($userAgent, $this->userAgentsWithDeviceID)) {
            return $this->userAgentsWithDeviceID[$userAgent];
        }

        return WurflConstants::NO_MATCH;
    }
947156
public function applyConclusiveMatch($userAgent)
    {
        $tolerance = Utils::toleranceToRisDelimeter($userAgent);

        if ($tolerance !== false) {
            return $this->getDeviceIDFromRIS($userAgent, $tolerance);
        }

        //Return no match for UAs with no extractable Android version, model and that do not start with either Mozilla or Dalvik
        if (!Utils::checkIfStartsWithAnyOf($userAgent, array('Mozilla', 'Dalvik'))) {
            return WurflConstants::NO_MATCH;
        }

        if (self::getAndroidModel($userAgent, false) === null) {
            return $this->getDeviceIDFromRIS($userAgent, strlen($userAgent));
        }

        // Standard RIS Matching
        $tolerance = Utils::indexOfAnyOrLength($userAgent, array(' Build/', ' AppleWebKit'));

        return $this->getDeviceIDFromRIS($userAgent, $tolerance);
    }
709243
public function setUserAgent($userAgent)
    {
        if (is_null($userAgent)) {
            foreach ($this->getUaHttpHeaders() as $altHeader) {
                if (isset($this->httpHeaders[$altHeader])) {
                    $userAgent .= $this->httpHeaders[$altHeader].' ';
                }
            }
        }

        return $this->userAgent = $userAgent;
    }
647610
public function applyRecoveryMatch($userAgent)
    {
        $isOperaMobi   = Utils::checkIfContains($userAgent, 'Opera Mobi');
        $isOperaTablet = Utils::checkIfContains($userAgent, 'Opera Tablet');

        if ($isOperaMobi || $isOperaTablet) {
            $androidVersion       = AndroidHandler::getAndroidVersion($userAgent);
            $androidVersionString = str_replace('.', '_', $androidVersion);
            $type                 = $isOperaTablet ? 'tablet' : 'mobi';
            $deviceID             = 'generic_android_ver' . $androidVersionString . '_opera_' . $type;

            if (in_array($deviceID, self::$constantIDs)) {
                return $deviceID;
            } else {
                return $isOperaTablet ? 'generic_android_ver2_1_opera_tablet' : 'generic_android_ver2_0_opera_mobi';
            }
        }

        return WurflConstants::NO_MATCH;
    }
780993
public function applyRecoveryMatch($userAgent)
    {
        $tolerance = Utils::indexOfOrLength($userAgent, '/', strpos($userAgent, 'Samsung'));

        return $this->getDeviceIDFromRIS($userAgent, $tolerance);
    }
1197156
public function applyConclusiveMatch($userAgent)
    {
        $find      = 'NetFrontLifeBrowser/2.2';
        $tolerance = strpos($userAgent, $find) + strlen($find);

        if ($tolerance > strlen($userAgent)) {
            $tolerance = strlen($userAgent);
        }

        return $this->getDeviceIDFromRIS($userAgent, $tolerance);
    }
1126522
public static function getWindowsPhoneDesktopVersion($userAgent)
    {
        if (preg_match('|Windows NT (\d+\.\d+)|', $userAgent, $matches)) {
            if (strpos($matches[1], '10.0') !== false) {
                return '10.0';
            } elseif (strpos($matches[1], '6.3') !== false || strpos($matches[1], '8.1') !== false) {
                return '8.1';
            } else {
                return '8.0';
            }
        }

        return null;
    }
520600
public function device($userAgent = null)
    {
        $rules = static::mergeRules(
            static::getDesktopDevices(),
            static::getPhoneDevices(),
            static::getTabletDevices(),
            static::getUtilities()
        );

        return $this->findDetectionRulesAgainstUA($rules, $userAgent);
    }
463296
public function getRules($userAgent = null)
    {
        // return all rules
        if ($userAgent === null) {
            return $this->rules;
        }
        $this->setUserAgent($userAgent);
        if (isset($this->rules[$this->userAgentMatch])) {
            return $this->rules[$this->userAgentMatch];
        }
        $this->log[] = 'Rules not found for the given User-Agent';
        return array();
    }
438841
public function normalize(string $userAgent): string
    {
        if (preg_match('/(ca|fr)\-crawler/', $userAgent)) {
            return $userAgent;
        }

        $regex = '/(; ?)(a[defgilmoqrstuwxz]|b[abdefghijlmnoqrstvwyz]|c[acdfghiklmnoruvwxyz]|d[ejkmoz]|e[ceghnrst]|f[ijkmor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdefghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eosuw]|s[abcdeghijklmnorstvxyz]|t[cdfghjklmnortvwz]|u[agmsyz]|v[aceginu]|w[fs]|y[et]|z[ahmw])([-_]r?[a-zA-Z]{2})?(\.utf8|\.big5)?(\b-?)(?!:)([;)])/';

        if (!preg_match($regex, $userAgent, $matches)) {
            return $userAgent;
        }

        $replacement = str_replace(
            ['; )', '; -;', '; ;', ';;'],
            [')', ';', ';', ';'],
            sprintf('%s%s%s%s', $matches[1], $matches[4], $matches[5], $matches[6])
        );

        return preg_replace($regex, $replacement, $userAgent);
    }
968430
public static function getHTCMacModel($userAgent)
    {
        if (preg_match('/(HTC[^;\)]+)/', $userAgent, $matches)) {
            $model = preg_replace('#[ _\-/]#', '~', $matches[1]);

            return $model;
        }

        return null;
    }
925943
public function getUserAgentObject($userAgent = null)
    {
        if (!$userAgent) {
            $userAgent = $this->getUserAgentByRequest();
        }
        $objectData = ArrayHelper::merge(
            ['class' => 'yii\useragentparser\UserAgentObject','userAgent'=>$userAgent],
            $this->parseUserAgent($userAgent)
        );

        return Yii::createObject($objectData);
    }
1371908
public function normalize(string $userAgent): string
    {
        $userAgent = preg_replace('/([\d]+)EMobile/', '$1; IEMobile', $userAgent);

        $userAgent = str_replace(
            ['Macintoshntel', 'cpu=PPC=Mac'],
            ['Macintosh; Intel', 'cpu=PPC;os=Mac'],
            $userAgent
        );

        $userAgent = preg_replace('/([\\\\]+)/i', '', $userAgent);
        $userAgent = preg_replace('/Versio\//', 'Version/', $userAgent);

        $userAgent = str_replace(
            ['i686 (x86_64)', 'X11buntu', 'Chr0me'],
            ['i686 on x86_64', 'X11; Ubuntu', 'Chrome'],
            $userAgent
        );

        return $userAgent;
    }
397074
public static function getUcAndroidModel($userAgent)
    {
        // Locales are optional for matching model name since UAs like Chrome Mobile do not contain them
        if (!preg_match('#Adr [\d\.]+; [a-zA-Z]+-[a-zA-Z]+; (.*)\) U2#', $userAgent, $matches)) {
            return null;
        }

        $model = $matches[1];

        // HTC
        if (strpos($model, 'HTC') !== false) {
            // Normalize "HTC/"
            $model = preg_replace('#HTC[ _\-/]#', 'HTC~', $model);
            // Remove the version
            $model = preg_replace('#(/| +V?\d)[\.\d]+$#', '', $model);
            $model = preg_replace('#/.*$#', '', $model);
        }

        // Samsung
        $model = preg_replace('#(SAMSUNG[^/]+)/.*$#', '$1', $model);
        // Orange
        $model = preg_replace('#ORANGE/.*$#', 'ORANGE', $model);
        // LG
        $model = preg_replace('#(LG-[A-Za-z0-9\-]+).*$#', '$1', $model);
        // Serial Number
        $model = preg_replace('#\[[\d]{10}\]#', '', $model);

        $model = trim($model);

        return (strlen($model) === 0) ? null : $model;
    }
1189022
public function getDeviceForUserAgent($userAgent)
    {
        if (!isset($userAgent)) {
            $userAgent = '';
        }
        
        $request = $this->_requestFactory->createRequestForUserAgent($userAgent);
        return $this->getDeviceForRequest($request);
    }