Converts from to to packagist.drupal-composer.org to D.O format.

@param string $version_constraint
The packagist.drupal-composer.org style version constraint.

@return string
The to packages.drupal.org/8 style constraint.
166845
protected static function convertVersionConstraint($version_constraint) {

    /*
     * 8.2.x-dev => 2.x-dev
     * 8.x-2.x-dev => 2.x-dev
     * 8.2.x-dev#a1b2c3 => 2.x-dev#a1b2c3
     * 8.x-2.x-dev#a1b2c3 => 2.x-dev#a1b2c3
     */
    if (preg_match('/-dev(#[0-9a-f]+)?$/', $version_constraint)) {
      return preg_replace('/^8\.(x-)?/', NULL, $version_constraint);
    }
    /*
     * dev-master => master-dev
     * dev-8.x-1.x => 1.x-dev
     * dev-8.x-1.x#abc123 => 1.x-dev#abc123
     * dev-8.2.x => 2.x-dev
     * dev-8.2.x#abc123 => 2.x-dev#abc123
     * dev-something_else#123abc => something_else-dev#123abc
     */
    if (strpos($version_constraint, 'dev-') === 0) {
      return preg_replace('/^dev-(8\.(x-)?)?([^#]+)(#[a-f0-9]+)?$/', '$3-dev$4', $version_constraint);
    }
    /*
     * 8.* => *
     */
    if (preg_match('/^8\.\*$/', $version_constraint)) {
      return "*";
    }
    /*
     * ~8 => *@stable
     * ^8 => *@stable
     */
    if (preg_match('/^[\^~]8$/', $version_constraint)) {
      return '*@stable';
    }
    /*
     * ~8.1.0-alpha1 > ~1.0.0-alpha1
     * ^8.1.0-alpha1 > ^1.0.0-alpha1
     * ^8.1.0 > ^1.0
     * 8.1.0-alpha1 > 1.0.0-alpha1
     * 8.1.0-beta12 > 1.0.0-beta12
     * 8.12.0-rc22 > 12.0.0-rc22
     */
    if (preg_match('/^([\^~]|[><=!]{1,2})?8(\.)?(\d+)?(\.\d+)?(-(alpha|beta|rc)\d+)?(\.\*)?(@(dev|alpha|beta|rc))?/', $version_constraint, $matches)) {
      /*
       * Group 0. `~8.1.0-alpha1.*@alpha`
       * Group 1. `~`
       * Group 2. `.`
       * Group 3. `1`
       * Group 4. `.0`
       * Group 5. `-alpha1`
       * Group 6. `alpha`
       * Group 7. `.*`
       * Group 8. `@alpha`
       * Group 9. `alpha`
       */
      $new_version_constraint = $matches[3];
      if (isset($matches[4])) {
        $new_version_constraint .= $matches[4];
      }
      if (isset($matches[3])) {
        $new_version_constraint .= '.0';
      }
      else {
        $new_version_constraint .= '*';
      }
      if (isset($matches[5])) {
        $new_version_constraint .= $matches[5];
      }
      elseif (isset($matches[7])) {
        $new_version_constraint .= $matches[7];
      }
      if (isset($matches[8])) {
        $new_version_constraint .= $matches[8];
      }
      if (isset($matches[1])) {
        $new_version_constraint = $matches[1] . $new_version_constraint;
      }
      return $new_version_constraint;
    }
    return $version_constraint;
  }
1193601
public function getTypeIfExist(Constraint $constraint)
    {
        return $this->hasPayloadDoc($constraint)
            ? $this->getPayloadDocValue($constraint, self::PAYLOAD_DOCUMENTATION_TYPE_KEY)
            : null
        ;
    }
321541
protected function getLoadPackagePathes($package, Version $version)
    {
        $packageName = $package instanceof Package ? $package->getName() : $package;
        $basePath = 'vendor' . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, explode('/', $packageName));
        $paths = array('directories' => array(), 'files' => array());
        foreach ($version->getAutoload() as $type => $map) {
            switch ($type) {
                case 'classmap':
                    $paths['directories'] = array_merge($paths['directories'], (array)$map);
                    break;
                case 'psr-0':
                    foreach ($map as $ns => $src) {
                        $nsPath = implode(DIRECTORY_SEPARATOR, explode('\\', str_replace('\\\\', '\\', $ns)));
                        foreach ((array)$src as $path) {
                            $paths['directories'][] = rtrim($path, '/') . DIRECTORY_SEPARATOR . $nsPath;
                        }
                    }
                    break;
                case 'psr-4':
                    foreach ($map as $ns => $src) {
                        foreach ((array)$src as $path) {
                            $paths['directories'][] = implode(DIRECTORY_SEPARATOR, explode('/', rtrim($path, '/')));
                        }
                    }
                    break;
                case 'files':
                    $paths['files'] = array_merge($paths['files'], (array)$map);
            }
        }

        $pathsToExclude = $this->excludeFilesInPath($basePath);
        $pathsToExclude = array_map(function ($p) use ($basePath) {
            return realpath($basePath . DIRECTORY_SEPARATOR . $p);
        }, $pathsToExclude);
        $pathsToExclude = array_filter($pathsToExclude, function ($p) {
            return $p !== false;
        });

        foreach ($paths as &$maps) {
            $maps = array_unique(array_values($maps));
            $maps = array_map(function ($p) use ($basePath) {
                return realpath($basePath . DIRECTORY_SEPARATOR . $p);
            }, $maps);
            foreach ($pathsToExclude as $p) {
                foreach ($maps as $index => $map) {
                    if (strpos($map, $p) === 0) {
                        unset($maps[$index]);
                    }
                }
            }
        }

        return $paths;
    }
1080929
public static function convertVersionMetadata($version)
    {
        $version = str_replace(self::$cleanPatterns, '', $version);

        if (preg_match_all(
            self::createPattern('([a-zA-Z]+|(\-|\+)[a-zA-Z]+|(\-|\+)[0-9]+)'),
            $version,
            $matches,
            PREG_OFFSET_CAPTURE
        )) {
            list($type, $version, $end) = self::cleanVersion(strtolower($version), $matches);
            list($version, $patchVersion) = self::matchVersion($version, $type);

            $matches = array();
            $hasPatchNumber = preg_match('/[0-9]+\.[0-9]+|[0-9]+|\.[0-9]+$/', $end, $matches);
            $end = $hasPatchNumber ? $matches[0] : '1';

            if ($patchVersion) {
                $version .= $end;
            }
        }

        return static::cleanWildcard($version);
    }
595540
protected function _getPrimaryConstraint(Constraint\Primary $constraint)
    {
        $columns = implode(', ', $constraint->getColumnNames());
        return sprintf(
            'CONSTRAINT %s PRIMARY KEY (%s)',
            $constraint->getName(),
            $columns
        );
    }
738282
public static function toVersion($version)
    {
        $components = self::toComponents($version);

        return new Version(
            $components['major'],
            $components['minor'],
            $components['patch'],
            $components['pre'],
            $components['build']
        );
    }
317312
def format_python_constraint(constraint):
    
    if isinstance(constraint, Version):
        if constraint.precision >= 3:
            return "=={}".format(str(constraint))

        # Transform 3.6 or 3
        if constraint.precision == 2:
            # 3.6
            constraint = parse_constraint(
                "~{}.{}".format(constraint.major, constraint.minor)
            )
        else:
            constraint = parse_constraint("^{}.0".format(constraint.major))

    if not isinstance(constraint, VersionUnion):
        return str(constraint)

    formatted = []
    accepted = []

    for version in PYTHON_VERSION:
        version_constraint = parse_constraint(version)
        matches = constraint.allows_any(version_constraint)
        if not matches:
            formatted.append("!=" + version)
        else:
            accepted.append(version)

    # Checking lower bound
    low = accepted[0]

    formatted.insert(0, ">=" + ".".join(low.split(".")[:2]))

    return ", ".join(formatted)
1436
private static function parseValid(Composer $composer, $class, $constraint)
    {
        if ($constraint === null) {
            return false;
        }

        $provides = $composer->getPackage()->getProvides();
        $boltVersion = isset($provides['bolt/bolt']) ? $provides['bolt/bolt'] : new Link('__root__', 'bolt/bolt', new Constraint('=', '0.0.0'));

        return $class && Semver::satisfies($boltVersion->getPrettyConstraint(), $constraint);
    }
1338915
public static function createFrame($version)
    {
        $width = self::$capacity[$version][Constants::QRCAP_WIDTH];
        $frameLine = str_repeat ("\0", $width);
        $frame = array_fill(0, $width, $frameLine);

        // Finder pattern
        self::putFinderPattern($frame, 0, 0);
        self::putFinderPattern($frame, $width - 7, 0);
        self::putFinderPattern($frame, 0, $width - 7);

        // Separator
        $yOffset = $width - 7;

        for($y=0; $y<7; $y++) {
            $frame[$y][7] = "\xc0";
            $frame[$y][$width - 8] = "\xc0";
            $frame[$yOffset][7] = "\xc0";
            $yOffset++;
        }

        $setPattern = str_repeat("\xc0", 8);

        QRstr::set($frame, 0, 7, $setPattern);
        QRstr::set($frame, $width-8, 7, $setPattern);
        QRstr::set($frame, 0, $width - 8, $setPattern);

        // Format info
        $setPattern = str_repeat("\x84", 9);
        QRstr::set($frame, 0, 8, $setPattern);
        QRstr::set($frame, $width - 8, 8, $setPattern, 8);

        $yOffset = $width - 8;

        for($y=0; $y<8; $y++,$yOffset++) {
            $frame[$y][8] = "\x84";
            $frame[$yOffset][8] = "\x84";
        }

        // Timing pattern

        for($i=1; $i<$width-15; $i++) {
            $frame[6][7+$i] = chr(0x90 | ($i & 1));
            $frame[7+$i][6] = chr(0x90 | ($i & 1));
        }

        // Alignment pattern
        self::putAlignmentPattern($version, $frame, $width);

        // Version information
        if($version >= 7) {
            $vinf = self::getVersionPattern($version);

            $v = $vinf;

            for($x=0; $x<6; $x++) {
                for($y=0; $y<3; $y++) {
                    $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));
                    $v = $v >> 1;
                }
            }

            $v = $vinf;
            for($y=0; $y<6; $y++) {
                for($x=0; $x<3; $x++) {
                    $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));
                    $v = $v >> 1;
                }
            }
        }

        // and a little bit...
        $frame[$width - 8][8] = "\x81";

        return $frame;
    }
1016471
public function importVersion($version)
    {
        return $this
            ->setMajor($version->getMajor())
            ->setMinor($version->getMinor())
            ->setPatch($version->getPatch())
            ->setPreRelease($version->getPreRelease())
            ->setBuild($version->getBuild());
    }
558765
public function guessMinLengthForConstraint(Constraint $constraint)
    {
        switch (get_class($constraint)) {
            case 'Symfony\Component\Validator\Constraints\Length':
                if (is_numeric($constraint->min)) {
                    return new ValueGuess($constraint->min, Guess::HIGH_CONFIDENCE);
                }
                break;
            case 'Symfony\Component\Validator\Constraints\Type':
                if (in_array($constraint->type, array('double', 'float', 'numeric', 'real'))) {
                    return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
                }
                break;
            case 'Symfony\Component\Validator\Constraints\Range':
                if (is_numeric($constraint->min)) {
                    return new ValueGuess(strlen((string) $constraint->min), Guess::LOW_CONFIDENCE);
                }
                break;
        }
    }
238559
public function visitHostnameFormatConstraint(StringValue\HostnameFormatConstraint $constraint)
    {
        if (!$this->formatValidationEnabled()) {
            return $this->createResult();
        }

        $value = $this->currentValue();
        if (
            !$value instanceof Value\StringValue ||
            $this->hostnameValidator()->isValid($value->value())
        ) {
            return $this->createResult();
        }

        return $this->createSingleIssueResult($constraint);
    }
410761
public static function isMatch($constraint, Version $version, &$failures = array())
    {
        foreach (explode(',', $constraint) as $constraintExpression) {
            $c = self::fromString($constraintExpression);
            if (!$c->match($version)) {
                $failures[]= "Constraint '$constraintExpression' failed";
            }
        }
        return count($failures) === 0;
    }
13566
protected function printPendingVersion(Version $version, $style)
    {
        /** @var Version $version */
        $id = $version->getId();
        $reflectionClass = new \ReflectionClass($version->getMigration());
        $absolutePath = $reflectionClass->getFileName();
        $fileName = $absolutePath ? $this->getRelativePath(getcwd(), $absolutePath) : '';
        $this->output->writeln("\t<$style>[$id] $fileName</$style>");
    }
777763
public function CMSVersionNumber()
    {
        $moduleName = array_keys($this->getVersionProvider()->getModules())[0];
        $lockModules = $this->getVersionProvider()->getModuleVersionFromComposer([$moduleName]);

        if (!isset($lockModules[$moduleName])) {
            return '';
        }

        return $lockModules[$moduleName];
    }
559799
private static function _versionToEKB(int $version): int
    {
        static $lut;
        if ($version > 255) {
            return $version;
        }
        if (!isset($lut)) {
            $lut = array_flip(self::EKB_TABLE);
        }
        return $lut[$version];
    }
477380
public function encodeMode8($version)
    {
        try {
            $bs = new QRbitstream();

            $bs->appendNum(4, 0x4);
            $bs->appendNum(QRspec::lengthIndicator(Constants::QR_MODE_8, $version), $this->size);

            for($i=0; $i<$this->size; $i++) {
                $bs->appendNum(8, ord($this->data[$i]));
            }

            $this->bstream = $bs;
            return 0;

        } catch (Exception $e) {
            return -1;
        }
    }