v1.0 Initial commit of project

This commit is contained in:
2026-01-01 10:54:18 +01:00
commit 768cf78b57
990 changed files with 241213 additions and 0 deletions

View File

@@ -0,0 +1,109 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\String\Resources;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\String\Exception\RuntimeException;
use Symfony\Component\VarExporter\VarExporter;
use Symfony\Contracts\HttpClient\HttpClientInterface;
/**
* @internal
*/
final class WcswidthDataGenerator
{
private HttpClientInterface $client;
public function __construct(
private string $outDir,
) {
$this->client = HttpClient::createForBaseUri('https://www.unicode.org/Public/UNIDATA/');
}
public function generate(): void
{
$this->writeWideWidthData();
$this->writeZeroWidthData();
}
private function writeWideWidthData(): void
{
if (!preg_match('/^# EastAsianWidth-(\d+\.\d+\.\d+)\.txt/', $content = $this->client->request('GET', 'EastAsianWidth.txt')->getContent(), $matches)) {
throw new RuntimeException('The Unicode version could not be determined.');
}
$version = $matches[1];
if (!preg_match_all('/^([A-H\d]{4,})(?:\.\.([A-H\d]{4,}))? +; [W|F]/m', $content, $matches, \PREG_SET_ORDER)) {
throw new RuntimeException('The wide width pattern did not match anything.');
}
$this->write('wcswidth_table_wide.php', $version, $matches);
}
private function writeZeroWidthData(): void
{
if (!preg_match('/^# DerivedGeneralCategory-(\d+\.\d+\.\d+)\.txt/', $content = $this->client->request('GET', 'extracted/DerivedGeneralCategory.txt')->getContent(), $matches)) {
throw new RuntimeException('The Unicode version could not be determined.');
}
$version = $matches[1];
if (!preg_match_all('/^([A-H\d]{4,})(?:\.\.([A-H\d]{4,}))? *; (?:Me|Mn)/m', $content, $matches, \PREG_SET_ORDER)) {
throw new RuntimeException('The zero width pattern did not match anything.');
}
$this->write('wcswidth_table_zero.php', $version, $matches);
}
private function write(string $fileName, string $version, array $rawData): void
{
$content = $this->getHeader($version).'return '.VarExporter::export($this->format($rawData)).";\n";
if (!file_put_contents($this->outDir.'/'.$fileName, $content)) {
throw new RuntimeException(\sprintf('The "%s" file could not be written.', $fileName));
}
}
private function getHeader(string $version): string
{
$date = (new \DateTimeImmutable())->format('c');
return <<<EOT
<?php
/*
* This file has been auto-generated by the Symfony String Component for internal use.
*
* Unicode version: $version
* Date: $date
*/
EOT;
}
private function format(array $rawData): array
{
$data = array_map(static function (array $row): array {
$start = $row[1];
$end = $row[2] ?? $start;
return [hexdec($start), hexdec($end)];
}, $rawData);
usort($data, static fn (array $a, array $b): int => $a[0] - $b[0]);
return $data;
}
}

View File

@@ -0,0 +1,59 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Symfony\Component\String\Resources\WcswidthDataGenerator;
if ('cli' !== \PHP_SAPI) {
throw new Exception('This script must be run from the command line.');
}
error_reporting(\E_ALL);
set_error_handler(static function (int $type, string $msg, string $file, int $line): void {
throw new ErrorException($msg, 0, $type, $file, $line);
});
set_exception_handler(static function (Throwable $exception): void {
echo "\n";
$cause = $exception;
$root = true;
while (null !== $cause) {
if (!$root) {
echo "Caused by\n";
}
echo $cause::class.': '.$cause->getMessage()."\n";
echo "\n";
echo $cause->getFile().':'.$cause->getLine()."\n";
echo $cause->getTraceAsString()."\n";
$cause = $cause->getPrevious();
$root = false;
}
});
$autoload = __DIR__.'/../../vendor/autoload.php';
if (!file_exists($autoload)) {
echo wordwrap('You should run "composer install" in the component before running this script.', 75)." Aborting.\n";
exit(1);
}
require_once $autoload;
echo "Generating wcswidth tables data...\n";
(new WcswidthDataGenerator(dirname(__DIR__).'/data'))->generate();
echo "Done.\n";

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,38 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\String;
if (!\function_exists(u::class)) {
function u(?string $string = ''): UnicodeString
{
return new UnicodeString($string ?? '');
}
}
if (!\function_exists(b::class)) {
function b(?string $string = ''): ByteString
{
return new ByteString($string ?? '');
}
}
if (!\function_exists(s::class)) {
/**
* @return UnicodeString|ByteString
*/
function s(?string $string = ''): AbstractString
{
$string ??= '';
return preg_match('//u', $string) ? new UnicodeString($string) : new ByteString($string);
}
}