CoreFiles by mySites.guru
generateCaseFoldingArray.php54 lines, 1,243 bytes, from Joomla_6.3.0-alpha1-Alpha-Full_Package.zip
Raw History Compare with 6.2.0-alpha3
md5
d8c84c35ca0d8518b892dd264ea8de10
sha1
0d0a58fb653b7bcb56cce6f21d6f5249a0a2b2ff
sha256
a33f0712a31242870b6d61b2b14d73055afdf4f084c2e33c0bda129b78b9137e
<?php

$inputFile = __DIR__ . '/CaseFolding.txt';
$outputFile = __DIR__ . '/../src/NamePrep/CaseFoldingData.php';

$map = [];

// Datei zeilenweise lesen
foreach (file($inputFile) as $line) {
    // Kommentare und leere Zeilen überspringen
    if (empty($line) || $line[0] === '#') {
        continue;
    }

    [$code, $status, $mapping] = array_map('trim', explode(';', $line));

    // ignore mapping irrelevant for IDNA2008
    if (!in_array($status, ['C', 'F'], true)) {
        continue;
    }
    // For IDNA2008, ß must not be case-folded to "ss"
    if (strtoupper($code) === '00DF') {
        continue;
    }

    $from = hexdec($code);
    $to = array_map('hexdec', explode(' ', $mapping));

    $map[$from] = $to;
}

$output = '<?php

declare(strict_types=1);

namespace Algo26\IdnaConvert\NamePrep;

/**
 * @codeCoverageIgnore character maps
 */
class CaseFoldingData implements CaseFoldingDataInterface
{
    public array $foldingMap = [
';
foreach ($map as $from => $to) {
    $fromHex = sprintf('0x%X', $from);
    $toHex = array_map(fn($v) => sprintf('0x%X', $v), $to);

    $output .= '        ' . $fromHex . ' => [' . join(', ', $toHex) .'],' . PHP_EOL;
}
$output .= '    ];
}
';
file_put_contents($outputFile, $output);

The same content is in 50 releases, Joomla 6.0.0-beta1 to 6.3.0-alpha1. See them all, or every version of this file.