From 163411410d03d2962f1d7bab3edb8fecf6cc3b38 Mon Sep 17 00:00:00 2001 From: Raffaele Carelle <raffaele.carelle@algoritma.it> Date: Fri, 11 Oct 2024 17:14:32 +0200 Subject: [PATCH 1/3] [String] Add `AbstractString::pascal()` method --- AbstractString.php | 5 +++++ CHANGELOG.md | 5 +++++ Tests/AbstractAsciiTestCase.php | 27 +++++++++++++++++++++++++++ Tests/AbstractUnicodeTestCase.php | 11 +++++++++++ 4 files changed, 48 insertions(+) diff --git a/AbstractString.php b/AbstractString.php index 500d7c3..fc60f8f 100644 --- a/AbstractString.php +++ b/AbstractString.php @@ -438,6 +438,11 @@ public function kebab(): static return $this->snake()->replace('_', '-'); } + public function pascal(): static + { + return $this->camel()->title(); + } + abstract public function splice(string $replacement, int $start = 0, ?int $length = null): static; /** diff --git a/CHANGELOG.md b/CHANGELOG.md index ff505b1..ac4b8fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.3 +--- + +* Add the `AbstractString::pascal()` method + 7.2 --- diff --git a/Tests/AbstractAsciiTestCase.php b/Tests/AbstractAsciiTestCase.php index ee4890f..e673f27 100644 --- a/Tests/AbstractAsciiTestCase.php +++ b/Tests/AbstractAsciiTestCase.php @@ -1118,6 +1118,33 @@ public static function provideKebab(): array ]; } + /** + * @dataProvider providePascal + */ + public function testPascal(string $expectedString, string $origin) + { + $instance = static::createFromString($origin)->pascal(); + + $this->assertEquals(static::createFromString($expectedString), $instance); + $this->assertNotSame($origin, $instance, 'Strings should be immutable'); + } + + public static function providePascal(): array + { + return [ + ['', ''], + ['XY', 'x_y'], + ['XuYo', 'xu_yo'], + ['SymfonyIsGreat', 'symfony_is_great'], + ['Symfony5IsGreat', 'symfony_5_is_great'], + ['SymfonyIsGreat', 'Symfony is great'], + ['SYMFONYISGREAT', 'SYMFONY_IS_GREAT'], + ['SymfonyIsAGreatFramework', 'Symfony is a great framework'], + ['SymfonyIsGREAT', '*Symfony* is GREAT!!'], + ['SYMFONY', 'SYMFONY'], + ]; + } + /** * @dataProvider provideStartsWith */ diff --git a/Tests/AbstractUnicodeTestCase.php b/Tests/AbstractUnicodeTestCase.php index bde19d7..2433f89 100644 --- a/Tests/AbstractUnicodeTestCase.php +++ b/Tests/AbstractUnicodeTestCase.php @@ -655,6 +655,17 @@ public static function provideCamel() ); } + public static function providePascal(): array + { + return array_merge( + parent::providePascal(), + [ + ['SymfonyIstÄußerstCool', 'symfonyIstÄußerstCool'], + ['SymfonyWithEmojis', 'Symfony with 😃 emojis'], + ] + ); + } + public static function provideSnake() { return array_merge( From 373a11f2d03e71934a0023888edf3328a583e4ec Mon Sep 17 00:00:00 2001 From: Fabien Potencier <fabien@potencier.org> Date: Sun, 5 Jan 2025 17:34:30 +0100 Subject: [PATCH 2/3] Fix typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac4b8fb..0782ae2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ CHANGELOG 7.3 --- -* Add the `AbstractString::pascal()` method + * Add the `AbstractString::pascal()` method 7.2 --- From a75110076ac661a4a52792b5a1d286d113653a70 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski <dariusz.ruminski@gmail.com> Date: Fri, 21 Feb 2025 02:28:48 +0100 Subject: [PATCH 3/3] chore: PHP CS Fixer - allow header validator --- Resources/WcswidthDataGenerator.php | 7 +++++++ Resources/data/wcswidth_table_wide.php | 7 +++++++ Resources/data/wcswidth_table_zero.php | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/Resources/WcswidthDataGenerator.php b/Resources/WcswidthDataGenerator.php index 19e6e89..005b148 100644 --- a/Resources/WcswidthDataGenerator.php +++ b/Resources/WcswidthDataGenerator.php @@ -83,10 +83,17 @@ private function getHeader(string $version): string <?php /* + * This file is part of the Symfony package. + * + * (c) Fabien Potencier <fabien@symfony.com> + * * This file has been auto-generated by the Symfony String Component for internal use. * * Unicode version: $version * Date: $date + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ diff --git a/Resources/data/wcswidth_table_wide.php b/Resources/data/wcswidth_table_wide.php index 6a75094..b2c94c3 100644 --- a/Resources/data/wcswidth_table_wide.php +++ b/Resources/data/wcswidth_table_wide.php @@ -1,10 +1,17 @@ <?php /* + * This file is part of the Symfony package. + * + * (c) Fabien Potencier <fabien@symfony.com> + * * This file has been auto-generated by the Symfony String Component for internal use. * * Unicode version: 16.0.0 * Date: 2024-09-11T08:21:22+00:00 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ return [ diff --git a/Resources/data/wcswidth_table_zero.php b/Resources/data/wcswidth_table_zero.php index fdd7f3c..287c36c 100644 --- a/Resources/data/wcswidth_table_zero.php +++ b/Resources/data/wcswidth_table_zero.php @@ -1,10 +1,17 @@ <?php /* + * This file is part of the Symfony package. + * + * (c) Fabien Potencier <fabien@symfony.com> + * * This file has been auto-generated by the Symfony String Component for internal use. * * Unicode version: 16.0.0 * Date: 2024-09-11T08:21:22+00:00 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ return [