diff --git a/build/BlocksBuilder/Block.php b/build/BlocksBuilder/Block.php index 3ab9ced..372a74e 100644 --- a/build/BlocksBuilder/Block.php +++ b/build/BlocksBuilder/Block.php @@ -4,6 +4,7 @@ namespace MLUnipoints\Build\BlocksBuilder; +use MLUnipoints\Info\BlockInfo; use MLUnipoints\Plane; class Block @@ -16,9 +17,6 @@ public function __construct( public readonly string $name, public readonly Plane $plane, ) { - $this->codename = strtr($this->name, [ - ' ' => '_', - '-' => '', - ]); + $this->codename = BlockInfo::buildCodename($this->name); } } diff --git a/build/CodepointsBuilder/Codepoint.php b/build/CodepointsBuilder/Codepoint.php index 51481d1..3e53ac3 100644 --- a/build/CodepointsBuilder/Codepoint.php +++ b/build/CodepointsBuilder/Codepoint.php @@ -6,6 +6,7 @@ use MLUnipoints\Build\BlocksBuilder\Block; use MLUnipoints\Category; +use MLUnipoints\Info\CodepointInfo; class Codepoint { @@ -18,11 +19,6 @@ public function __construct( public readonly Category $category, public readonly Block $block, ) { - $this->codename = strtr($this->name, [ - ', ' => '__', - ' -' => '__', - ' ' => '_', - '-' => '_', - ]); + $this->codename = CodepointInfo::buildCodename($this->name); } } diff --git a/src/Info/BlockInfo.php b/src/Info/BlockInfo.php index 6aa296e..be1db94 100644 --- a/src/Info/BlockInfo.php +++ b/src/Info/BlockInfo.php @@ -11,12 +11,16 @@ #[\Attribute(\Attribute::TARGET_CLASS_CONSTANT)] class BlockInfo { + public readonly string $codename; + public function __construct( public readonly int $fromCodepoint, public readonly int $toCodepoint, public readonly string $name, public readonly Plane $plane, - ) {} + ) { + $this->codename = self::buildCodename($this->name); + } public static function from(Block $block): self { @@ -24,4 +28,15 @@ public static function from(Block $block): self return $reflection->getAttributes(self::class)[0]->newInstance(); } + + /** + * @internal + */ + public static function buildCodename(string $name): string + { + return strtr($name, [ + ' ' => '_', + '-' => '', + ]); + } } diff --git a/src/Info/CodepointInfo.php b/src/Info/CodepointInfo.php index 48de905..c09cb90 100644 --- a/src/Info/CodepointInfo.php +++ b/src/Info/CodepointInfo.php @@ -12,6 +12,8 @@ #[\Attribute(\Attribute::TARGET_CLASS_CONSTANT)] class CodepointInfo { + public readonly string $codename; + public function __construct( public readonly int $id, public readonly string $name, @@ -63,7 +65,9 @@ public function __construct( * @var string[] */ public readonly array $abbreviations = [], - ) {} + ) { + $this->codename = self::buildCodename($this->name); + } public static function from(BackedEnum $codepoint): self { @@ -71,4 +75,17 @@ public static function from(BackedEnum $codepoint): self return $reflection->getAttributes(self::class)[0]->newInstance(); } + + /** + * @internal + */ + public static function buildCodename(string $name): string + { + return strtr($name, [ + ', ' => '__', + ' -' => '__', + ' ' => '_', + '-' => '_', + ]); + } }