Compare two version as string.

It supports wildcard in one of the version

@param string $version1
@param string $version2

@return int 0 if equal, -1 if $version1 < $version2, 1 if $version1 > $version2
178420
public static function compareVersion($version1, $version2)
    {
        if ($version1 == $version2) {
            return 0;
        }

        $v1 = Parser::parse($version1);
        $v2 = Parser::parse($version2);

        return self::compare($v1, $v2);
    }
699254
public function match(Version $version)
    {
        $versionStabilityIndex = array_search($version->getStability(), Version::$stabilities);
        $constraintStabilityIndex = array_search($this->stability, Version::$stabilities);

        if ($this->compare($versionStabilityIndex, $constraintStabilityIndex) !== 0) {
            return false;
        }

        $numericValues = $version->numeric();
        $comparisons = array();

        foreach ($this->version as $i => $value) {
            $comparisons[$i] = $this->compare($numericValues[$i], $value);
        }

        switch ($this->operator) {
            case '=': case '==':
                // all parts must be equal:
                return array_filter($comparisons) === array();
                break;
            case '!': case '!=':
                // any part must be unequal:
                return array_filter($comparisons) !== array();
                break;
            case '>=':
            case '<=':
            case '>':
            case '<':
                // the first mismatch is the tie breaker
                $mismatches = array_filter($comparisons);
                if (!count($mismatches)) {
                    // if no mismatches, only ok if equality operator
                    return in_array($this->operator, array('<=', '>='));
                } else {
                    $first = array_shift($mismatches);
                    return
                           ($this->operator === '<'  && $first < 0)
                        || ($this->operator === '<=' && $first < 0)
                        || ($this->operator === '>'  && $first > 0)
                        || ($this->operator === '>=' && $first > 0)
                    ;
                }
        }

        throw new \UnexpectedValueException("An unknown edge case was encountered. Is the constraint valid?");
    }
212549
public static function Compare ($string1, $string2, $encoding = Encoding::DEFAULT_ENCODING) {
		return strcmp(Encoding::Adjust($string1, $encoding), Encoding::Adjust($string2, $encoding));
	}
1227377
public static function compareStr($str1, $str2) {
		$len1 = static::binaryStrlen($str1);
		$len2 = static::binaryStrlen($str2);
		$len = min($len1, $len2);
		$diff = $len1 ^ $len2;

		for ($i = 0; $i < $len; $i++) {
			$diff |= ord($str1[$i]) ^ ord($str2[$i]);
		}

		return $diff === 0;
	}
647761
public static function compareTimeWithoutDate($date1, $date2)
    {
        $date1 = DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-01 ' . $date1->format('H:i:s'));
        $date2 = DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-01 ' . $date2->format('H:i:s'));
        if ($date1 == $date2) {
            return 0;
        }
        if ($date1 < $date2) {
            return -1;
        }

        return 1;
    }
423527
public static function getDifference(Release $release1, Release $release2 = null)
    {
        if ($release2 === null) {
            return self::MAJOR;
        }

        $version1 = explode('.', $release1->getVersion());
        $version2 = explode('.', $release2->getVersion());
        if (isset($version1[0]) === false || isset($version2[0]) === false || $version1[0] != $version2[0]) {
            return self::MAJOR;
        } elseif (isset($version1[1]) === false || isset($version2[1]) === false || $version1[1] != $version2[1]) {
            return self::MINOR;
        } elseif (isset($version1[2]) === false || isset($version2[2]) === false || $version1[2] != $version2[2]) {
            return self::PATCH;
        }
    }
202610
public function getCharacterCountBits(Version $version) : int
    {
        $number = $version->getVersionNumber();

        if ($number <= 9) {
            $offset = 0;
        } elseif ($number <= 26) {
            $offset = 1;
        } else {
            $offset = 2;
        }

        return $this->characterCountBitsForVersions[$offset];
    }
1260910
protected function buildVersion($versionString, $matches)
    {
        $versionString = $this->buildByMatch($versionString, $matches);
        $versionString = str_replace('_', '.', $versionString);
        if (null !== self::$maxMinorParts && substr_count($versionString, '.') > self::$maxMinorParts) {
            $versionParts = explode('.', $versionString);
            $versionParts = array_slice($versionParts, 0, 1+self::$maxMinorParts);
            $versionString = implode('.', $versionParts);
        }
        return trim($versionString, ' .');
    }
414023
public static function smallerThan(Version $v1, Version $v2)
    {
        // If it's equal it can not be smaller
        if (self::equals($v1, $v2)) {
            return false;
        }

        // If it's not equal, and not greater, it must be smaller
        return !self::greaterThan($v1, $v2);
    }
1167507
protected function compare($schedule1, $schedule2)
    {
        $run1 = $schedule1->getNextRunDate();
        $run2 = $schedule2->getNextRunDate();
        if ($run1 < $run2) {
            return 1;
        } elseif ($run1 > $run2) {
            return -1;
        }

        return 0;
    }
821412
public function containsVersionOfFile($file, $version)
    {
        $f = $this->findVersionOfFile($file, $version);
        return  $f != null;
    }
480957
public function supportsVersion(Version $version) : bool
    {
        try {
            $this->getVersionUrl($version);
        } catch (UnsupportedVersionException $e) {
            return false;
        }

        return true;
    }
94417
public function compareFiles($file1, $file2)
    {
        if ($file1 == $file2) {
            return 0;
        }

        $sortOrder = $this->getFileSortOrder();

        if (!isset($sortOrder[$file1]) && !isset($sortOrder[$file2])) {
            return 0;
        }

        if (isset($sortOrder[$file1]) && !isset($sortOrder[$file2])) {
            return -1;
        }

        if (!isset($sortOrder[$file1]) && isset($sortOrder[$file2])) {
            return 1;
        }

        if ($sortOrder[$file1] < $sortOrder[$file2]) {
            return -1;
        }

        if ($sortOrder[$file1] > $sortOrder[$file2]) {
            return 1;
        }

        return 0;
    }
437788
public static function compare($version)
    {
        $currentVersion = str_replace(' ', '', strtolower(self::VERSION));
        $version        = str_replace(' ', '', $version);

        return version_compare($version, $currentVersion);
    }
908865
public static function Equal ($string1, $string2, $encoding = Encoding::DEFAULT_ENCODING) {
		return (self::Compare($string1, $string2, $encoding) === 0);
	}
311387
protected static function extractVersion(string $version, string $expression): ?string
    {
        if (preg_match($expression, $version, $result)) {
            return Arr::first($result);
        }

        return null;
    }
1023106
public function findVersionOfFile($file, $version)
    {
        if($file == null || ($f2 = $this->findOriginalFileToVersion($file)) == null ||
            $file->getAbsoluteFilePath() != $f2->getAbsoluteFilePath()){
            return null;
        }
        $name = $this->versionFileName($file, $version);
        $f = new FileImpl($file->getParentFolder()->getAbsolutePath()."/".$name);
        return $this->containsFile($f)?$f:null;
    }